array_intersect() Definition and Usage
array_intersect() function returns the intersection array of two or more arrays.
The result array contains all values that are in the compared array and also appear in all other parameter arrays, and the key names remain unchanged.
Note: Only values are used for comparison.
Syntax
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 | Optional. The array to compare to the first array. There can be multiple. |
Copy code The code is as follows:
$a1=array(0=>"Cat",1=>"Dog",2=> "Horse");
$a2=array(3=>"Horse",4=>"Dog",5=>"Fish");
print_r(array_intersect($a1,$a2));
?>
The above introduces the twinkle twinkle little star PHP array function sequence array_intersect returns the intersection array of two or more arrays, including the content of twinkle twinkle little star. I hope it will be helpful to friends who are interested in PHP tutorials.