array_intersect_assoc in PHP

Syntax of array_intersect_assoc in PHP

array array_intersect_assoc(array array1, array array2[, … array arrayN])

Returns an array containing all the values present in all of the given arrays. Unlike array_inter sect(), both the keys and values must match to be considered identical. The keys of the values are preserved

Example of array_intersect_assoc

<?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);
?>

Output of array_intersect_assoc

Array
(
    [a] => green
)

Leave a Comment