note 75677 deleted from ref.array by levim
| From: | levim@php.net | Date: | Tue, 06 May 2014 22:05:02 +0000 |
| Subject: | note 75677 deleted from ref.array by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-199455@lists.php.net to get a copy of this message | ||
Note Submitter: webdev at svbeatrix dot com
----
Bugs happen, but how can people post functions that WON'T EVEN COMPILE! I truly detest finding
a cool code snippet or function and then having to debug them. Sorry for the rant, but I have
experienced this scenario a number of times. TEST YOUR CODE, THEN POST!
Here is a revised and corrected previously posted function ArrayDepth, which had 3 bugs and yes,
would not compile.
function ArrayDepth($Array,$DepthCount=-1) {
// Find maximum depth of an array
// Usage: int ArrayDepth( array $array )
// returns integer with max depth
// if Array is a string or an empty array it will return 0
$DepthArray=array(0);
$DepthCount++;
$Depth = 0;
if (is_array($Array))
foreach ($Array as $Key => $Value) {
$DepthArray[]=ArrayDepth($Value,$DepthCount);
}
else
return $DepthCount;
return max($DepthCount,max($DepthArray));
}