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:
- How to filter an associative array comparing keys with values in an indexed array?
- 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 to remove a variable from a PHP session array
- Will copy-on-write prevent data duplication on arrays?
- Is PHP’s count() function O(1) or O(n) for arrays?
- How do I select 10 random things from a list in PHP?