Home > Backend Development > PHP Tutorial > PHP array function sequence array_intersect() returns the intersection array of two or more arrays_PHP tutorial

PHP array function sequence array_intersect() returns the intersection array of two or more arrays_PHP tutorial

WBOY
Release: 2016-07-21 15:23:00
Original
1030 people have browsed it

array_intersect() Definition and Usage

array_intersect() function returns the intersection array of two or more arrays.

The result array contains all values ​​in the compared array that 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...)

参数 描述
array1 必需。与其他数组进行比较的第一个数组。
array2 必需。与第一个数组进行比较的数组。
array3 可选。与第一个数组进行比较的数组。可以有多个。

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 )

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324563.htmlTechArticlearray_intersect() Definition and usage array_intersect() function returns the intersection array of two or more arrays. The result array contains everything in the compared array, and also appears in all other...
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