You can cross the array. This finds all the values ββof array2 that are in array 1
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); $array2 = array("a" => "green", "yellow", "red"); $result_array = array_intersect_assoc($array1, $array2); print_r($result_array);
Will return
Array ( [a] => green )
It returns an array with all keys and match values. Basically you can provide an infinite number of array_insert_assoc arguments:
array_intersect_assoc($base_array, $arr1, $arr2 ...);
It will look for $base_array for values ββthat are in all subsequent arrays. This means that the key and value will be taken from $base_array
You can also compare keys using:
array_intersect_keys($base_array, $arr1, $arr2, $arr3);
source share