[thelist] PHP Multidimensional Array Keys

Burhan Khalid thelist at meidomus.com
Tue Sep 30 05:54:05 CDT 2003


Gavin Lilley wrote:
[ snipped array ]
> To loop through the array I can do this:
> while (list($key, $value) = each ($unitArray)) { echo "[$key ][
> $value ]<br>";}
> But I do not know how to 'drill down' through the array. Whats wrong with
> the following code?
> 
> while (list($key, $value) = each ($unitArray)) {
>  echo "[$key ][ $value ]<br>";
>     while (list($keyA, $valueA) = each ($unitArray[$key])) {
>      echo "[$keyA ][ $valueA ]<br>";
>     }
> }
> 

In short, you are checking the wrong thing. The $key isn't the array, 
the $value is the array. For example, for the key 2, the value is an array.

So you should check to see if the value is an array. If it is, then step 
through it, etc.

http://www.php.net/is-array

Hope this helps :)

-- 
Burhan Khalid
thelist[at]meidomus[dot]com
http://www.meidomus.com



More information about the thelist mailing list