I have following arrays:
$keys
array (size=2)
0 => string 'foo' (length=3)
1 => string 'buz' (length=3)
$data
array (size=3)
'foo' => int 1
'bar' => int 2
'buz' => int 3
How to get $data
array filtered by $keys
values ? Desired output:
array (size=3)
'foo' => int 1
'buz' => int 3
array_intersect_key
should be able to help you out here
array_intersect_key($data, array_flip($keys));
The array_flip
is needed because array_intersect_key
operates on keys, so this makes sure both arrays are in the right format.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments