note 79749 added to ref.array

From: Date: Tue, 11 Dec 2007 11:13:31 +0000
Subject: note 79749 added to ref.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-133359@lists.php.net to get a copy of this message
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; } } } ?> ---- Server IP: 61.195.146.164 Probable Submitter: 219.118.191.50 ---- Manual Page -- http://www.php.net/manual/en/ref.array.php Edit -- https://master.php.net/note/edit/79749 Del: integrated -- https://master.php.net/note/delete/79749/integrated Del: useless -- https://master.php.net/note/delete/79749/useless Del: bad code -- https://master.php.net/note/delete/79749/bad+code Del: spam -- https://master.php.net/note/delete/79749/spam Del: non-english -- https://master.php.net/note/delete/79749/non-english Del: in docs -- https://master.php.net/note/delete/79749/in+docs Del: other reasons-- https://master.php.net/note/delete/79749 Reject -- https://master.php.net/note/reject/79749 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#133359) next »