Array_intersect_assoc
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
array_intersect_assoc-with index Check the intersection of computed arrays
Description
Array Array_intersect_assoc (array $array 1, array $array 2 [, array $ ...])
ARRAY_INTERSECT_ASSOC () returns an array that contains all the values in Array1 that also appear in all other parameter arrays. Note that unlike Array_intersect (), the key name is also used for comparison.
Parameters
Array1
The primary value to check.
Array2
The array to compare.
...
The list of array variables to compare.
return value
Returns an array that contains all the values in Array1 that also appear in all other parameter arrays.
Example
Example #1 Array_intersect_assoc () example
<?php
$array 1 = Array ("A" = "green", "b" = "Brown", "c" = "blue", "Red");
$array 2 = Array ("A" = "green", "b" = "yellow", "blue", "Red");
$result _array = Array_intersect_assoc ($array 1, $array 2);
Print_r ($result _array);
?>
The above routines will output:
Array
(
[A] = Green
)
As you can see in the above example, only the key value pairs "a" and "green" are present in two arrays and are returned. The value "Red" is not returned because in $array 1 Its key name is 0 and in $array 2 The key name of "Red" is 1, the key " B " is not returned because its value differs from other arrays.
The key value pair key = Two values in value are considered equal only when (string) $elem 1 = = = (string) $elem 2 . This means that strict checks are used, and the expression of the strings must be the same.
See
PHP---ARRAY_INTERSECT_ASSOC