@@ -96,7 +96,7 @@ function reduce(iterable $array, callable $callback, mixed $initial = null): mix
9696 }
9797
9898 /**
99- * Gets a value from the array and remove it.
99+ * Gets a value by its key from the array and remove it. Mutates the array .
100100 *
101101 * @template TKey of array-key
102102 * @template TValue
@@ -107,7 +107,7 @@ function reduce(iterable $array, callable $callback, mixed $initial = null): mix
107107 function pull (array &$ array , string |int $ key , mixed $ default = null ): mixed
108108 {
109109 $ value = get_by_key ($ array , $ key , $ default );
110- $ array = namespace \remove ($ array , $ key );
110+ $ array = namespace \forget_keys ($ array , $ key );
111111
112112 return $ value ;
113113 }
@@ -127,15 +127,37 @@ function shuffle(iterable $array): array
127127 }
128128
129129 /**
130- * Alias of {@see \Tempest\Support\Arr\remove}.
130+ * Removes the specified keys from the array. The array is not mutated.
131+ *
132+ * @template TKey of array-key
133+ * @template TValue
134+ *
135+ * @param array<TKey,TValue> $array
136+ * @param array-key|array<array-key> $keys The keys of the items to remove.
137+ * @return array<TKey,TValue>
138+ */
139+ function remove_keys (iterable $ array , string |int |array $ keys ): array
140+ {
141+ return namespace \forget_keys (to_array ($ array ), $ keys );
142+ }
143+
144+ /**
145+ * Removes the specified values from the array. The array is mutated.
146+ *
147+ * @template TKey of array-key
148+ * @template TValue
149+ *
150+ * @param array<TKey,TValue> $array
151+ * @param TValue|array<TValue> $values The values to remove.
152+ * @return array<TKey,TValue>
131153 */
132- function forget ( iterable $ array , string |int |array $ keys ): array
154+ function remove_values ( array $ array , string |int |array $ values ): array
133155 {
134- return namespace \remove (to_array ($ array ), $ keys );
156+ return namespace \forget_values (to_array ($ array ), $ values );
135157 }
136158
137159 /**
138- * Removes the specified items from the array.
160+ * Removes the specified keys from the array. The array is mutated .
139161 *
140162 * @template TKey of array-key
141163 * @template TValue
@@ -144,7 +166,7 @@ function forget(iterable $array, string|int|array $keys): array
144166 * @param array-key|array<array-key> $keys The keys of the items to remove.
145167 * @return array<TKey,TValue>
146168 */
147- function remove (array $ array , string |int |array $ keys ): array
169+ function forget_keys (array $ array , string |int |array $ keys ): array
148170 {
149171 $ keys = is_array ($ keys ) ? $ keys : [$ keys ];
150172
@@ -155,6 +177,29 @@ function remove(array $array, string|int|array $keys): array
155177 return $ array ;
156178 }
157179
180+ /**
181+ * Removes the specified values from the array. The array is mutated.
182+ *
183+ * @template TKey of array-key
184+ * @template TValue
185+ *
186+ * @param array<TKey,TValue> $array
187+ * @param TValue|array<TValue> $values The values to remove.
188+ * @return array<TKey,TValue>
189+ */
190+ function forget_values (array $ array , string |int |array $ values ): array
191+ {
192+ $ values = is_array ($ values ) ? $ values : [$ values ];
193+
194+ foreach ($ values as $ value ) {
195+ if (! is_null ($ key = array_find_key ($ array , fn (mixed $ match ) => $ value === $ match ))) {
196+ unset($ array [$ key ]);
197+ }
198+ }
199+
200+ return $ array ;
201+ }
202+
158203 /**
159204 * Asserts whether the array is a list.
160205 * An array is a list if its keys consist of consecutive numbers.
0 commit comments