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
function isDeepMultiArray($multiarray, $level = 2) { if (is_array($multiarray)) { if ($level == 1) { return true; } foreach ($multiarray as $array) { if (isDeepMultiArray($array, $level - 1)) { $message = "I'm a multiarray"; return $message; } } } else { return false; }
}
if (isDeepMultiArray(array(array()), 2)); ?>
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.