Home >Backend Development >PHP Tutorial >php-Arrays function-array_intersect_key-calculate the intersection of arrays using key name comparison_PHP tutorial
array_intersect_key() uses key name comparison to calculate the intersection of arrays
【Function】
This function will return an array,
This array contains all values in array1 that are not in any other parameter array.
【Scope of use】
php5>php5.1.0 .
【Use】
array array_intersect_key( array array1, array array2[,array...] )
array1/required/array1
array2/required/comparable array must have at least one
array.../optional/array used for comparison
【Example】
[php]
//Define two arrays respectively
$array1 = array( "blue" => 6, "red" => 2, "green" => 3, "purple" => 4 );
$array2 = array( "green"=>5 , "blue" => 6, "yellow" => 7, "cyan" => 8 );
print_r( array_intersect_key( $array1, $array2 ) );
/*
Array
(
[blue] => 6
[green] => 3
)*/
[php]
Excerpted from zuodefeng’s notes