Home  >  Article  >  Backend Development  >  twinkle twinkle little star php array function sequence array_intersect returns the intersection array of two or more arrays

twinkle twinkle little star php array function sequence array_intersect returns the intersection array of two or more arrays

WBOY
WBOYOriginal
2016-07-29 08:47:161076browse

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.

Example

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));
?>


Output:
Array ( [1] => Dog [2] => Horse )

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.

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