【问题标题】:Loop through nested array PHP循环遍历嵌套数组 PHP
【发布时间】:2015-03-02 17:09:37
【问题描述】:

我有以下结构(我使用 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}}

如何访问“表单”属性?

【问题讨论】:

  • 您是如何尝试访问它的,您在尝试访问该属性时是否遇到错误?

标签: php arrays json loops


【解决方案1】:

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

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

【讨论】:

  • 谢谢!正是我需要的答案。完美运行!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-01
相关资源
最近更新 更多