Skip to content

Commit 88390ac

Browse files
committed
add Arrays::remove
1 parent 1d3df3e commit 88390ac

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/Arrays.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,35 @@
1212
class Arrays
1313
{
1414

15+
/**
16+
* @template K
17+
* @template V
18+
* @param array<K, V> $values
19+
* @return array<K, V>
20+
*/
21+
public static function remove(array $values, mixed $value, int $limit = -1): array
22+
{
23+
foreach ($values as $key => $val) {
24+
if ($val === $value) {
25+
unset($values[$key]);
26+
27+
if ($limit !== -1 && (--$limit <= 0)) {
28+
break;
29+
}
30+
}
31+
}
32+
33+
return $values;
34+
}
35+
1536
public static function allows(array $values, array $keys): array
1637
{
1738
$return = [];
1839

1940
foreach ($keys as $key) {
2041
$return[$key] = $values[$key] ?? null;
2142
}
22-
43+
2344
return $return;
2445
}
2546

src/ExceptionHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static function didYouMean(array $posibilities, string $value): string
1111
{
1212
$suggestion = Helpers::getSuggestion($posibilities, $value);
1313

14-
if ($suggestion !== null) {
14+
if (!$suggestion) {
1515
return '.';
1616
}
1717

0 commit comments

Comments
 (0)