2

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?

1 Answer 1

2

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'];
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.