I have 2 arrays.
<?php
$array1 = array('id' => 1, 'email' => 'example@example.com' , 'name' => 'john' );
$array2 = array('id', 'email');
i am having trouble writing a code to unset the key value pair from array1 that is not from array 2.
The problem with this is unlike most examples, my array2 does not have a format of a key value pair but only key.
How do i go about removing things from array1 that is not specified in array2.
my current code is not working
foreach ($array1 as $key => $value) {
if (array_search($key, $array2)===false) {
unset($key);
}
}