0

假设我有这个:

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 数组的信息,但它似乎只是简单的示例。

4

2 回答 2

4

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

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

于 2012-09-16T20:47:17.650 回答
1

如果您想要/需要手动执行此操作:

<?php

$achievementData = new array();

$achievementData[] = new array('id' => 0, 'title' => 'abc', 'description' => 'abc', 'xp' => 500, 'level_req' => 3);

// repeat the same for the other records

?>
于 2012-09-16T20:52:35.413 回答