File tree Expand file tree Collapse file tree 1 file changed +7
-13
lines changed Expand file tree Collapse file tree 1 file changed +7
-13
lines changed Original file line number Diff line number Diff line change 11
11
namespace Secretary \Helper ;
12
12
13
13
/**
14
- * Class ArrayHelper.
15
- *
16
14
* @package Secretary\Helper
17
15
*/
18
16
abstract class ArrayHelper
@@ -33,22 +31,18 @@ public static function without(array $array, ...$keys): array
33
31
}
34
32
35
33
/**
34
+ * Remove elements from an array based on a list of keys and return a new array with the removed elements.
35
+ *
36
36
* @param string ...$keys
37
37
*/
38
- public static function remove (array & $ array , ...$ keys ): array
38
+ public static function remove (array $ array , ...$ keys ): array
39
39
{
40
- $ newArray = [];
41
- foreach (array_keys ($ newArray ) as $ key ) {
42
- if (!in_array ($ key , $ keys )) {
43
- $ newArray [$ key ] = $ array [$ key ];
44
- unset($ array [$ key ]);
45
- }
46
- }
40
+ // Create a copy of the array to avoid modifying the original array
41
+ $ newArray = $ array ;
47
42
43
+ // Iterate over the keys and remove them from the new array
48
44
foreach ($ keys as $ key ) {
49
- if (!array_key_exists ($ key , $ newArray )) {
50
- $ newArray [$ key ] = null ;
51
- }
45
+ unset($ newArray [$ key ]);
52
46
}
53
47
54
48
return $ newArray ;
You can’t perform that action at this time.
0 commit comments