From 1bc7ad1eb0073b3e4db44d44df68c4e67976ded1 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Thu, 12 Dec 2024 15:23:01 +0100 Subject: [PATCH] [TASK] Array utility: Add depth function --- Classes/Utility/ArrayUtility.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Classes/Utility/ArrayUtility.php b/Classes/Utility/ArrayUtility.php index 0c0da26..c763526 100644 --- a/Classes/Utility/ArrayUtility.php +++ b/Classes/Utility/ArrayUtility.php @@ -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; + } + }