With array_intersect_key
and array_flip
:
var_dump(array_intersect_key($my_array, array_flip($allowed)));
array(1) {
["foo"]=>
int(1)
}
More Related Contents:
- Filter array by its keys using an array of allowed keys
- Remove all elements from array that do not start with a certain string
- count how many duplicate keys are in array of objects?
- PHP – File to Associative Array with 1 key and two values attached
- How to combine two arrays together?
- Replace keys in an array based on another lookup/mapping array
- How to re-index the values of an array in PHP? [duplicate]
- Get difference between associative rows of two 2-dimensional arrays
- Characters allowed in php array keys?
- Recursively remove empty elements and subarrays from a multi-dimensional array
- Get the keys for duplicate values in an array
- PHP get both array value and array key
- How to find array / dictionary value using key?
- PHP – Find parent key of array
- Explode string into array with no empty elements?
- How to access first level keys of a 2d array with a foreach loop? [duplicate]
- Add elements to array which has gapped numeric keys to form an indexed array / list
- What is the max key size for an array in PHP?
- Native function to filter array by prefix
- Checking if ANY of an array’s elements are in another array
- Return only duplicated entries from an array (case-insensitive)
- Custom key-sort a flat associative based on another array
- Most efficient way to search for object in an array by a specific property’s value
- Rename key in each row of a 2d array
- Is there a way to change all keys in a flat indexed array to the same string (“Name”)? [closed]
- array_diff to compare two associative arrays
- how can I print multiple services in this way
- PHP Sort a multidimensional array by element containing Y-m-d H:i:s date
- How to bind mysqli bind_param arguments dynamically in PHP?
- Group array data on one column and sum data from another column