note 66811 added to function.is-array

From: Date: Tue, 30 May 2006 06:42:48 +0000
Subject: note 66811 added to function.is-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-112525@lists.php.net to get a copy of this message
Will check a Multi-Dimentional Array to any specified level. This is a fix to 11/16/05 submission, which would break since you must supply a foreach with an array. Beware recursive functions shouldn't go over 100 deep or could break the memory stack on server. <?php // checks for multiarray to defined depth level recursively // original $level must be 2 or more, else will instantly return true function isDeepMultiArray($multiarray, $level = 2) { // default is simple multiarray if (is_array($multiarray)) { // confirms array if ($level == 1) { // $level reaches 1 after specified # of recursions return true; // returns true to recursive function conditional } // end conditional foreach ($multiarray as $array) { // goes one level deeper into array if (isDeepMultiArray($array, $level - 1)) { // check subarray $message = "I'm a multiarray"; // optional message return $message; // best if $message = true so function returns boolean } // end recursive function } // end loop } else { // not an array at specified level return false; // is also used recursively so can't change to message } } if (isDeepMultiArray(array(array()), 2)); // beware this returns true eventhough arrays are empty ?> BTW my notation is consistent with the PEAR manual on coding standards, which is what php.net says to follow. I hope a function like this gets included in PHP6. ---- Server IP: 66.163.161.117 Probable Submitter: 68.104.56.193 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.is-array.php Edit -- http://master.php.net/note/edit/66811 Del: integrated -- http://master.php.net/note/delete/66811/integrated Del: useless -- http://master.php.net/note/delete/66811/useless Del: bad code -- http://master.php.net/note/delete/66811/bad+code Del: spam -- http://master.php.net/note/delete/66811/spam Del: non-english -- http://master.php.net/note/delete/66811/non-english Del: in docs -- http://master.php.net/note/delete/66811/in+docs Del: other reasons-- http://master.php.net/note/delete/66811 Reject -- http://master.php.net/note/reject/66811 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#112525) next »