假设我的 JSON 是这样的:
{
"achievement": [
{
"title": "All Around Submitter",
"description": "Get one piece of content approved in all six areas.",
"xp": 500,
"level_req": 1
},
{
"title": "World-wide Photo Journalist",
"description": "Get one photo approved in all six areas.",
"xp": 500,
"level_req": 1
},
{
"title": "Ready for Work",
"description": "Sign up and get validated",
"xp": 50,
"level_req": 1
},
{
"title": "Asian Pride",
"description": "Get ten pieces of content approved to a club in an Asian nation.",
"xp": 1500,
"level_req": 1
}
]
}
我的PHP代码是这样的,所以我通过那个json文件加载......:
<?php
$string = file_get_contents("achievements.json");
$json_a=json_decode($string,true);
foreach ($json_a as $key => $value){
echo $value[0]['title'] . " <br />";
}
?>
然而,它只输出第一个数组。我知道。只有 1. 但是foreach
循环呢?为什么它不是为每一行循环?