循环遍历嵌套数组PHP

时间:2015-03-02 17:09:37

标签: php arrays json loops

我有以下结构(我使用json_decode在PHP上循环它):

{"721":{"forms":0},"722":{"forms":"[82]","ope":"48723","ini":"01/03/2015 00:00","fin":"01/03/2015 00:20"},"723":{"forms":0},"724":{"forms":0},"725":{"forms":0},"726":{"forms":0},"727":{"forms":0},"729":{"forms":0},"730":{"forms":0},"731":{"forms":0}}

如何访问属性“表单”?

1 个答案:

答案 0 :(得分:0)

使用foreach循环遍历数组中的每个键/值对,然后只需访问value数组的forms属性。

$a = json_decode($stuff, true); // where $stuff is that JSON string
foreach ($a as $key => $value) {
    print $value['forms']."<br />"
}