[TASK] Array utility: Add depth function

This commit is contained in:
Philipp Dieter 2024-12-12 15:23:01 +01:00
parent 5c42fa2d1d
commit 1bc7ad1eb0

View File

@ -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;
}
}