Home  >  Article  >  Backend Development  >  How to learn PHP array_intersect_key()_PHP tutorial

How to learn PHP array_intersect_key()_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:23:561046browse

How to learn PHP array_intersect_key()

Definition and usage

The array_intersect_key() function calculates the intersection of arrays using key name comparison.

array_intersect_key() returns an array containing the values ​​of all key names that appear in the compared array and appear in all other parameter arrays.

Note: Only key names are used for comparison.

Grammar

array_intersect_key(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 1

"Cat",1=>"Dog",2=>"Horse"); $a2=array(2=>"Bird", 0=>"Cat",4=>"Fish"); print_r(array_intersect_key($a1,$a2)); ?>

Output:

Array ( [0] => Cat [2] => Horse )

Example 2

"Cat",1=>"Dog",2=>"Horse"); $a2=array(2=>"Bird", 3=>"Rat",4=>"Fish"); $a3=array(2=>"Dog",6=>"Cow",7=>"Bird"); print_r(array_intersect_key ($a1,$a2,$a3)); ?>

Output:

Array ( [2] => Horse )

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/834961.htmlTechArticleHow to learn PHP array_intersect_key() Definition and Usage The array_intersect_key() function uses key name comparison to calculate the intersection of arrays. array_intersect_key() returns an array containing...
Statement:
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