Home > Backend Development > PHP Tutorial > php-Arrays function-array_intersect-calculate the intersection of arrays_PHP tutorial

php-Arrays function-array_intersect-calculate the intersection of arrays_PHP tutorial

WBOY
Release: 2016-07-13 17:51:02
Original
1055 people have browsed it

array_intersect() calculates the intersection of arrays

【Function】
This function will return an array,
This array contains the values ​​of all keys that are in array1 but are not in any other parameter array.
                                                                                                    Note that the key names remain unchanged
【Scope of use】
​​​​​ php 4>4.0.1, php5.
【Use】
array array_intersect_ukey( array array1, array array2[,array...] )
           array1/required/array1
           array2/required/comparable array must have at least one
           array.../optional/array used for comparison
【Example】
[php]
//Define two arrays respectively
$array1 = array("blue"=>5,"red"=>2,"green"=>3,"purple"=>4);
$array2 = array("green"=>5,"blue"=>6,"yellow"=>7,"cyan"=>8);
var_dump(array_intersect( $array1,$array2));
/*
array(1) {
["blue"]=>
int(5)
}
*/


Excerpted from zuodefeng’s notes

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478211.htmlTechArticlearray_intersect() Calculate the intersection of arrays [Function] This function will return an array that contains all the elements in array1 in but not in any other parameter array. ...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template