php - JavaScript 到 PHP 数组

标签 php javascript

假设我有这个:

var achievementData = {
    "achievements": { 
        0: {
            "id": 0,
            "title": "All Around Submitter",
            "description": "Submit and approved one piece of content in all six areas.",
            "xp": 500,
            "level_req": 3
        }, 
        1: {
            "id": 1,
            "title": "Worldwide Photographer",
            "description": "Submit and approved one piece of image content in all six areas.",
            "xp": 1200,
            "level_req": 1
        }, 
        2: {
            "id": 2,
            "title": "Super Submitter",
            "description": "Get approved 10 players and 2 clubs in one week or less.",
            "xp": 2500,
            "level_req": 5
        }, 

        }
};

这是 JavaScript,那么我如何将其转换为 PHP?我尝试更改括号并查找有关 PHP 数组的信息,但看起来这只是简单的示例。

最佳答案

您应该使用 json_decode() 将该字符串转换为 php 中有用的内容,将第二个参数设置为 true 它将为您提供一个关联数组。

http://php.net/manual/en/function.json-decode.php

关于php - JavaScript 到 PHP 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12450577/

相关文章:

php - MySQL SELECT w/two AS id field names using php while mysql_fetch_array() to identify them uniquely

php - =& 是什么意思?

PHP 从数组中获取最高值(从 SQL 选择)

javascript - toggle() 不起作用并追加更多字段

javascript - 使用 Bootstrap 模式的 Youtube 视频

php - 产品具有属性(变体)数据库设计?

php - 当我编写自己的分页模板时如何避免分页器行项目

javascript - Android Native 浏览器中上传的空文件

javascript - 为什么将javascript文件包含在函数中?

javascript - 查看网页和桌面应用程序是否在同一台计算机上启动