如何在cakephp中使用foreach分解数组?

时间:2014-07-01 09:55:42

标签: php arrays

我想使用foreach循环分解下面的数组。

     "childs": {
          "bars-pubs": {
               "id": "7",
               "parent": "1",
               "name": "Bars & Pubs",
               "display_name": "Bars & Pubs",
               "alias": "bars-pubs",
               "image": null
          },
          "billards-bars": {
            "id": "8",
            "parent": "1",
            "name": "Billards Bars",
            "display_name": "Billards Bars",
            "alias": "billards-bars",
            "image": null
          },
          "bowling-allies": {
            "id": "9",
            "parent": "1",
            "name": "Bowling Allies",
            "display_name": "Bowling Allies",
            "alias": "bowling-allies",
            "image": null
          },
          "cigar-bar": {
             "id": "10",
             "parent": "1",
             "name": "Cigar Bar",
             "display_name": "Cigar Bar",
             "alias": "cigar-bar",
             "image": null
          },
      },

在上面的数组中,如果我使用foreach循环分解代码,它总是在childs下给我第一个数组。

1 个答案:

答案 0 :(得分:1)

$yourArray = array(
            "childs"=>array(
                            ...
                      )
            );

foreach($yourArray["childs"] as $child) {
    debug($child);
}