Home > Backend Development > PHP Tutorial > How to learn PHP array_intersect()_PHP tutorial

How to learn PHP array_intersect()_PHP tutorial

WBOY
Release: 2016-07-13 10:23:52
Original
856 people have browsed it

How to learn PHP array_intersect()

Definition and usage

The 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.

Grammar

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 is optional. The array to compare to the first array. There can be multiple.

Example

"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/834963.htmlTechArticleHow to learn PHP array_intersect() definition and usage array_intersect() function returns the intersection array of two or more arrays. The result array contains all the items in the compared array, and also appears...
Related labels:
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