array_intersect() Function is used to compare two (or more) arrays key value and return the intersection. This function compares the key values of two (or more) arrays and returns the intersection array, which includes all the arrays being compared (array1), as well as any other parameter arrays (array2 or array3 etc.).
array array_intersect ( array array1, array array2 [, array ...])
Let me show you the example from the manual:
<?php $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 )
The above is the detailed content of php array_intersect() function usage example. For more information, please follow other related articles on the PHP Chinese website!