Home >Backend Development >PHP Tutorial >php array_intersect() function usage example

php array_intersect() function usage example

怪我咯
怪我咯Original
2017-07-11 15:00:231280browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn