$array1 = ['key1'=>'val1', 'key2'=>'val2', 'key3'=>'val3']
$array2 = ['key1','key3']
I want to get all elements from array1 that has keys in array2. So the result should be:
$result = ['key1'=>'val1', 'key3'=>'val3']
I tried array_intersect_key($array1, $array2) but that doesn't work. What is the fastest way to get the above result?
Edit: Forgot to mention that array2 maybe a associative array or single dimension.