Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an array like so

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

What I am trying to grab is the src of reference image...I have tried the following

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

but it returns like so

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] => )

What do I have to do to add the reference image src to my new gallery array?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

What you have is a three dimensional array... you need to wrap this in another loop..

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

of if your top level array only ever has a single element you can just iterate of it

foreach($images[0] as $row => $value){
       $gallery[] = $value['image'];
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.