Home > Article > Backend Development > php array_intersect() function usage code_PHP tutorial
array array_intersect (array array1, array array2 [, array ...])
array_intersect() function returns the intersection array of two or more arrays.
array_intersect() returns an array containing all values in array1 that also appear in all other parameter arrays. Note that the key names remain unchanged.
Let me show you the example from the manual:
$array1 = array ("a" => "green", "red", " blue");
$array2 = array ("b" => "green", "yellow", "red");
$result = array_intersect ($array1, $array2);
print_r ($result);
?>
The output result is as follows:
Array
(
[a] => green
[0] => red
)