[TASK] Array utility: Add depth function
This commit is contained in:
parent
5c42fa2d1d
commit
1bc7ad1eb0
@ -67,4 +67,20 @@ class ArrayUtility
|
||||
return array_keys($arr) !== range(0, count($arr) - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the depth of an array
|
||||
*/
|
||||
function depth(array $array) {
|
||||
$depthMax = 1;
|
||||
foreach ($array as $value) {
|
||||
if (is_array($value)) {
|
||||
$depth = self::depth($value) + 1;
|
||||
if ($depth > $depthMax) {
|
||||
$depthMax = $depth;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $depthMax;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user