Given:
$data = array(
"some" => "163",
"rand" => "630",
"om" => "43",
"words" => "924",
"as" => "4",
"keys" => "54"
);
I want a new array using only the keys that match those certain keys:
$keys = array( "some", "thing", "rand", "keys" );
I'd like to return an array with those keys in common, creating:
$arr = array(
"some" => "163",
"rand" => "630",
"keys" => "54"
);
You can do this with array_intersect_key() and array_flip():
$arr = array_intersect_key($data, array_flip($keys));
Result:
Array
(
[some] => 163
[rand] => 630
[keys] => 54
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With