What is the array intersection function in php that only compares values?

青灯夜游
Release: 2023-03-15 21:34:01
Original
2171 people have browsed it

The array intersection function in PHP that only compares values is "array_intersect()"; this function is used to compare the key values of two (or more) arrays, the syntax is "array_intersect(array1, array2. ..)" will return an intersection array containing values taken from the compared array (array 1).

What is the array intersection function in php that only compares values?

The operating environment of this tutorial: Windows 7 system, PHP version 7.1, DELL G3 computer

The array intersection function in php that only compares values isarray_intersect().

array_intersect() function is used to compare two (or more) arrays. When comparing, only the key values of the arrays are compared and the intersection of the arrays is returned.

array_intersect(array1,array2,array3...);
Copy after login

array1,array2,array3...is the array list that needs to be compared

##Parameters Description Required. The first array to compare with other arrays. Required. The array to compare to the first array. Optional. Additional array to compare with the first array.
array1
array2
array3,...
Return value:

  • Returns an intersection array, which includes all the arrays being compared (array1), Also the value in any other parameter array (array2 or array3 etc.).

  • Simply put, the returned intersection value is obtained from the compared array (array1).

Example 1: Compare the values of two arrays and return the intersection:

What is the array intersection function in php that only compares values?

Example 2: Compare the values of three arrays , and return the intersection

"red","b"=>"green","c"=>"blue","d"=>"yellow"); $a2=array("e"=>"red","f"=>"black","g"=>"purple"); $a3=array("a"=>"red","b"=>"black","h"=>"yellow"); var_dump($a1); var_dump($a2); var_dump($a3); $result=array_intersect($a1,$a2,$a3); echo "交集数组:"; var_dump($result); ?>
Copy after login

What is the array intersection function in php that only compares values?

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of What is the array intersection function in php that only compares values?. 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!