-2

我正在尝试使用此代码循环第二个数组

        <?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 } ?>

我得到“非法字符串偏移...”错误。我知道在 foreach 中添加 [1] 可能是错误,但是我如何在第二个数组中创建循环呢?

数组内容

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)
              ...
4

1 回答 1

2

试着循环$categories[1]['children']

foreach ( $categories[1]['children'] as $category_cat ) { }
于 2013-09-12T14:21:56.253 回答