Definition and usage
The array_intersect() function returns the intersection array of two or more arrays.
The result array contains all values in the compared array that also appear in all other parameter arrays, and the key names remain unchanged.
Note: Only values are used for comparison.
Grammar
array_intersect(array1,array2,array3...)
Parameters
Description
array1 required. The first array to compare with other arrays.
array2 required. The array to compare to the first array.
array3 is optional. The array to compare to the first array. There can be multiple.
Example
"Cat",1=>"Dog",2=>"Horse"); $a2=array(3=>"Horse", 4=>"Dog",5=>"Fish"); print_r(array_intersect($a1,$a2)); ?>
Output:
Array ( [1] => Dog [2] => Horse )