diff options
Diffstat (limited to 'build/Arr.php')
| -rw-r--r-- | build/Arr.php | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/build/Arr.php b/build/Arr.php new file mode 100644 index 0000000..e9f357d --- /dev/null +++ b/build/Arr.php @@ -0,0 +1,26 @@ +<?php + +declare(strict_types=1); + +final class Arr +{ + /** + * Extract the specified keys from the given array. + * + * @param array<array-key, mixed> $array + * @param array<int, array-key> $keys + * @return array<array-key, mixed> + */ + public static function only(array $array, array $keys): array + { + $result = []; + + foreach ($keys as $key) { + if (array_key_exists($key, $array)) { + $result[$key] = $array[$key]; + } + } + + return $result; + } +} |
