Skip to content

Commit ab2cd83

Browse files
committed
Fixed remove method
1 parent f55379b commit ab2cd83

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Helper/ArrayHelper.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ public static function without(array $array, ...$keys): array
3737
*/
3838
public static function remove(array $array, ...$keys): array
3939
{
40-
// Create a copy of the array to avoid modifying the original array
41-
$newArray = $array;
40+
$newArray = [];
4241

43-
// Iterate over the keys and remove them from the new array
4442
foreach ($keys as $key) {
45-
unset($newArray[$key]);
43+
$newArray[$key] = $array[$key] ?? null;
44+
45+
if (!empty($array[$key])) {
46+
unset($array[$key]);
47+
}
4648
}
4749

4850
return $newArray;

0 commit comments

Comments
 (0)