note 79749 deleted from ref.array by felipe

From: Date: Sun, 30 Dec 2007 19:31:23 +0000
Subject: note 79749 deleted from ref.array by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-134537@lists.php.net to get a copy of this message
Note Submitter: sakai dot d4k at gmail dot com ---- Needed depth of the dimension for arrays might be different by cases, so I made this. The default of switch might not be 'max' though. <?php function array_dimension($array, $option = null) { if(!is_array($array)) { return 0; } elseif(!$array) { // if the element does not exist return 1; } else { switch(strtolower($option)) { case 'first': $keys = array_keys($array); return array_dimension($array[$keys[0]], $option) + 1; case 'last': $keys = array_keys($array); return array_dimension($array[$keys[count($keys) - 1]], $option) + 1; case 'min': foreach($array as $key => $val) { $dems[$key] = array_dimension($val, $option); } return min($dems) + 1; case 'max': default: foreach($array as $key => $val) { $dems[$key] = array_dimension($val, $option); } return max($dems) + 1; } } } ?>

« previous php.notes (#134537) next »