array_intersect_assoc

(PHP 4 >= 4.3.0, PHP 5, PHP 7)
Computes the intersection of arrays with additional index check
array array_intersect_assoc ( array $array1, array $array2 [, array $... ] )

array_intersect_assoc() returns an array containing all the values of array1 that are present in all the arguments. Note that the keys are used in the comparison unlike in array_intersect().

Parameters:
array1

The array with master values to check.

array2

An array to compare values against.

...

A variable list of arrays to compare.

Returns:

Returns an associative array containing all the values in array1 that are present in all of the arguments.

Examples:
array_intersect_assoc() 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);
?>

The above example will output:

Array
(
    [a] => green
)
See also:

array_intersect() -

array_uintersect_assoc() -

array_intersect_uassoc() -

array_uintersect_uassoc() -

array_diff() -

array_diff_assoc() -

doc_php
2016-02-24 16:12:45
Comments
Leave a Comment

Please login to continue.