forked from gtuxyco/shipping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
42 lines (33 loc) · 945 Bytes
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
declare(strict_types = 1);
use Vinnia\Util\Stack;
if (!function_exists('removeKeysWithValues')) {
/**
* @param array $source
* @param mixed[] $needles
* @return array
*/
function removeKeysWithValues(array $source, ...$needles): array
{
$stack = new Stack([&$source]);
while (!$stack->isEmpty()) {
$parts = $stack->pop();
$chunk = &$parts[0];
if (!is_array($chunk)) {
continue;
}
$clone = $chunk;
foreach ($clone as $key => $value) {
$matches = in_array($value, $needles, true);
if (is_array($value) && !$matches) {
$stack->push([&$chunk[$key]]);
continue;
}
if ($matches) {
unset($chunk[$key]);
}
}
}
return $source;
}
}