From c8555f5bed86667a7bd0f75d3014063d9ce965eb Mon Sep 17 00:00:00 2001 From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com> Date: Tue, 25 Mar 2025 11:11:09 +0100 Subject: [PATCH] use maps --- library/Utils.php | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/library/Utils.php b/library/Utils.php index 1c132ac..24e8309 100644 --- a/library/Utils.php +++ b/library/Utils.php @@ -13,20 +13,12 @@ class Utils */ public static function recursiveArrayFilter (array $array): array { - // First filter the array for non-empty elements - $filtered = array_filter($array, function ($item) { - if (is_array($item)) { - // Recursively filter the sub-array - $item = self::recursiveArrayFilter($item); - // Only retain non-empty arrays - return !empty($item); - } else { - // Retain non-empty scalar values + return array_filter($array, function ($item) { + if (is_array($item)) { + $item = self::recursiveArrayFilter($item); + } return !empty($item); - } }); - - return $filtered; } /** @@ -40,12 +32,10 @@ class Utils { $matching = []; - if (!empty($elements)) { - foreach ($elements as $element) { - foreach ($keys as $key) { - if (!empty($element) && array_key_exists($key, $element)) { - $matching[] = $key; - } + foreach ($elements as $element) { + foreach ($keys as $key) { + if (!empty($element) && array_key_exists($key, $element)) { + $matching[] = $key; } } } -- GitLab