Is there a function to return specific array keys?

I am wondering if there is a built-in PHP function to do the following:

Take two parameters: the input array and the second numerical array of key names and return only the keys from the input array whose name is in the second numerical array.

+1
source share
1 answer

You can use array_intersect_keyand array_flip:

array_intersect_key($arr, array_flip($keys))
+7
source

All Articles