$master = ['111' => 'foo', '124' => 'bar', '133' => 'baz'];
$check = ['111' => 14, '133' => 23 ]';
I want to remove all keys from $master
that do not exists in $check
.
So the result in this example should be:
$newMaster = ['111' => 'foo', '133' => 'baz'];
Any idea how to do this ? Thanks in advance.
Yes, simply use array_intersect_key()
$newMaster = array_intersect_key($master, $check);
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