Voting

: min(six, five)?
(Example: nine)

The Note You're Voting On

jupiter at nospam dot com
17 years ago
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.

<< Back to user notes page

To Top