Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_multiple_keys($arr, $keys = []){
- if(!$keys) return [];
- $result = [];
- array_walk($keys, function($key, &$val = null) use ($arr, &$result){
- if(isset($arr[$key])){
- $result[$key] = $arr[$key];
- }
- });
- return $result;
- }
- // Test
- $res = get_multiple_keys(['name' => 'Victor', 'age' => 24, 3 => 'Hello world!'], ['name', 'age', 3, 10, 'aaaa']);
- var_dump($res);
- // Result
- // -> array(3) { ["name"]=> string(5) "Victor" ["age"]=> int(24) [3]=> string(8) "Hello world" }
Advertisement
Add Comment
Please, Sign In to add comment