1

I have a multidimensional array, that is a few levels deep. I am trying to loop through some of the lower levels of array items, but when I do, it seems to only return one of the array items.

foreach ($items as $item) { foreach ($item as $id) { echo $id; } } 

For some reason, echoing $id only returns the first item in the $item array, how would I look through all items in the $item array, and echo those as well?

2 Answers 2

2

First, are you totally sure it is a multidimensional array? I'd try to check my $items structure using

print_r($items) 
Sign up to request clarification or add additional context in comments.

2 Comments

Hmmm. Well, $items has three items in it, each are an id. I then wanted to use that ID within the second foreach to return an array, specific to that ID. Maybe that is where I am going wrong?
If you don't want to dump to the buffer you can pass true, print_r($items, true) and it will return the print_r output as a string.
2

var_dump() is always my favorite.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.