array_intersect_assoc
array_intersect_assoc
Computes the intersection of arrays with additional index check
array **array_intersect_assoc** array $array array $arrays
returns an array
containing all the values of
that are present in all the arguments. Note that the keys are also used in
the comparison unlike in .
array_intersect_assoc``array``array_intersect
arrayThe array with master values to check.
arraysArrays to compare values against.
Returns an associative array containing all the values in
that are present in all of the arguments.
array
Voorbeeld: example
<?php
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "green", "b" => "yellow", "blue", "red");
$result_array = array_intersect_assoc($array1, $array2);
print_r($result_array);
?>
Array
(
[a] => green
)
In our example you see that only the pair is present in both arrays and thus is returned.
The value is not returned because in
its key is while
the key of "red" in is
, and the key is not returned
because its values are different in each array.
"a" => "green"``"red"``$array1``0``$array2``1``"b"
The two values from the pairs are considered equal only if . In other words a strict type check is executed so the string representation must be the same.
key => value``(string) $elem1 === (string) $elem2
array_intersect``array_uintersect_assoc``array_intersect_uassoc``array_uintersect_uassoc``array_diff``array_diff_assoc