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

php array_intersect() function usage example

怪我咯
Release: 2023-03-13 15:18:01
Original
1283 people have browsed it

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 ...])
Copy after login

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); 
?>
Copy after login

The output result is as follows:

Array 
( 
[a] => green 
[0] => red 
)
Copy after login

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!

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