-1

私はこのソースファイルを持っています。

[
    {
        "title": "Course1",
        "location": "BuildingA",
        "day": "wednesday",
        "id": 85412
    },
    {
        "title": "Course2",
        "location": "BuidlingB",
        "day": "friday",
        "id": 85413
    },
    {
        "title": "Course3",
        "location": "BuidlingA",
        "day": "friday",
        "id": 85414
    }
]

PHPで、キー「title」と「location」の値のみを出力するにはどうすればよいですか?

私がこれまでに持っているコードは次のとおりです。

$array = json_decode($json, true);

foreach ($array as $key => $jsons) {
     foreach($jsons as $key => $value)  
echo $value." ";
}
4

2 に答える 2

1
foreach ($array as $key => $jsons) {     
echo $jsons['title'];
echo $jsons['location'];
}
于 2013-01-28T08:58:06.830 に答える
0
$json = '
[
    {
        "title": "Course1",
        "location": "BuildingA",
        "day": "wednesday",
        "id": 85412
    },
    {
        "title": "Course2",
        "location": "BuidlingB",
        "day": "friday",
        "id": 85413
    },
    {
        "title": "Course3",
        "location": "BuidlingA",
        "day": "friday",
        "id": 85414
    }
]
';

$array = json_decode($json, true);

foreach ($array as $key => $jsons) {
echo $jsons["location"];
echo $jsons["title"];
}
于 2013-01-28T08:59:39.017 に答える