From 61d147755c1091bbf9b08b6792debd041a0286fd Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 29 Jan 2024 07:40:28 -0800 Subject: [PATCH] fix: ArrayHelper remove method --- src/Core/Helper/ArrayHelper.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Core/Helper/ArrayHelper.php b/src/Core/Helper/ArrayHelper.php index 122eb78..1301dc0 100644 --- a/src/Core/Helper/ArrayHelper.php +++ b/src/Core/Helper/ArrayHelper.php @@ -37,12 +37,14 @@ public static function without(array $array, ...$keys): array */ public static function remove(array $array, ...$keys): array { - // Create a copy of the array to avoid modifying the original array - $newArray = $array; + $newArray = []; - // Iterate over the keys and remove them from the new array foreach ($keys as $key) { - unset($newArray[$key]); + $newArray[$key] = $array[$key] ?? null; + + if (!empty($array[$key])) { + unset($array[$key]); + } } return $newArray;