views:

142

answers:

2

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  A: 

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

print_r($items)
nairdaen
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?
Nic Hubbard
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.
gradbot
+2  A: 

var_dump() is always my favorite.

shambleh