RE: [PHP] Is there a php built-in function to determine the number of dimensions of the array?

From: Date: Wed, 26 Nov 2003 13:09:20 +0000
Subject: RE: [PHP] Is there a php built-in function to determine the number of dimensions of the array?
Groups: php.general 
Request: Send a blank email to php-general+get-171047@lists.php.net to get a copy of this message
[snip] (ii) All PHP arrays are 1-dimensional. Some elements of an array may themselves contain arrays, but that only makes them nested arrays, not multi-dimensional. If what you want to know is the deepest level of nesting, then, no, I don't believe there's a built-in function for this. [/snip] From http://us3.php.net/manual/en/language.types.array.php here is an example of a multi-dimensional array <?php $fruits = array ( "fruits" => array ( "a" => "orange", "b" => "banana", "c" => "apple" ), "numbers" => array ( 1, 2, 3, 4, 5, 6 ), "holes" => array ( "first", 5 => "second", "third" ) ); // Some examples to address values in the array above echo $fruits["holes"][5]; // prints "second" echo $fruits["fruits"]["a"]; // prints "orange" unset($fruits["holes"][0]); // remove "first" Or more simply $arrayFoo[0][0][0] $arrayFoo[0][0][1] $arrayFoo[0][1][1] $arrayFoo[1][1][1]

« previous php.general (#171047) next »