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 で役立つものに変換する必要があります。2 番目のパラメーターを 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 に答える