我试图使用此代码
在第二个数组中循环 <?php
foreach ($categories[1] as $category_cat) { ?>
<li><a href="<?php echo $category_cat['href']; ?>"><span><?php echo $category_cat['name']; ?></span></a></li>
<?php } ?>
我得到了&#34;非法的字符串偏移...&#34;错误。我知道addind [1] foreach可能是错误但是我怎么能在第二个数组中制作循环呢?
数组内容
array (size=2)
0 =>
array (size=4)
'name' => string 'Brands' (length=7)
'children' =>
array (size=12)
0 =>
array (size=3)
...
1 =>
array (size=3)
...
2 =>
array (size=3)
...
3 =>
array (size=3)
...
4 =>
array (size=3)
...
5 =>
array (size=3)
...
6 =>
array (size=3)
...
7 =>
array (size=3)
...
8 =>
array (size=3)
...
9 =>
array (size=3)
...
10 =>
array (size=3)
...
11 =>
array (size=3)
...
'column' => string '1' (length=1)
'href' => string 'url here' (length=78)
1 =>
array (size=4)
'name' => string 'Catégories' (length=11)
'children' =>
array (size=7)
0 =>
array (size=3)
...
1 =>
array (size=3)
...
答案 0 :(得分:2)
试着循环$categories[1]['children']
:
foreach ( $categories[1]['children'] as $category_cat ) { }