George Botley Posted February 2, 2012 Share Posted February 2, 2012 Hi, Here's the array under the $img variable Array ( [0] => Array ( [url] => IMG_0002.JPG ) ) 1 It would normally have multiple values, depending on the amount the users adds to the form. Basically, for key '0' on the array I wish to then get the value of the sub array "url". How would I do this in a foreach loop? George. Quote Link to comment https://forums.phpfreaks.com/topic/256279-array-within-array-for-each/ Share on other sites More sharing options...
digibucc Posted February 2, 2012 Share Posted February 2, 2012 this will grab each entry in the array, and then you pull the named key (url) for that entry and do what you want, along with any other keys. it is best if your keys are always the same. <?php foreach ($array as $entry){ echo $entry['url']; // named array key in nested array } ?> or this will cycle through each entry, and then each value in the entry. it's cumbersome and not recommended unless you need to process each value THE SAME, separately. <?php foreach ($array as $entry){ foreach ($entry as info) { // do something with each piece of info, in each entry } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/256279-array-within-array-for-each/#findComment-1313805 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.