PHP从另一个数组中获取数组

时间:2013-07-18 16:10:52

标签: php arrays foreach

我有一个像这样的数组

Array (
   [0] => Array (
       [64579] => Array (
           [title] => title
           [description] => blah, blah, blah
           [image] => Array (
                [original] => Array ( [src] => image1.jpg )
                [reference] => Array ( [src] => image1_big.jpg )
                [thumb] => Array ( [src] => image1_thumb.jpg )
           )

我想要抓住的是参考图像的src ...我尝试了以下

foreach($images as $row => $value){
               $gallery[] = $value['image'];
}

但它会像这样返回

Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => [16] => [17] => [18] => [19] => [20] => [21] => [22] => [23] => [24] => [25] => [26] => [27] => [28] => [29] => [30] => [31] => [32] => [33] => [34] => [35] => [36] => [37] => [38] => [39] => [40] => [41] => [42] => [43] => [44] => [45] => [46] => [47] => [48] => )

如何将参考图像src添加到我的新图库数组?

1 个答案:

答案 0 :(得分:2)

你拥有的是一个三维数组......你需要将它包装在另一个循环中..

foreach($images as $imageGroupList)
    foreach($imageGroupList as $row => $value){
           $gallery[] = $value['image'];
    }
}

如果您的顶级数组只有一个元素,您可以只迭代它

foreach($images[0] as $row => $value){
       $gallery[] = $value['image'];
}