The array_intersect_assoc() is a builtin function in PHP and is used to compute the intersection of two or more arrays. This function is similar to the function array_intersect() which is discussed in the article PHP | array_intersect() function. The function is also used to compare the values of two or more arrays and returns the matches. The only difference is that the function returns all of the values of the first array that are present in all other arguments at the same index as that in first array, i.e., the keys are mainly used in the comparison.
array array_intersect_assoc($array1, $array2, $array3,...)
Parameters: The array_intersect_assoc() function takes atleast two arrays as parameter. The function can take any number of arrays as arguments greater than or equal to two.
Return Value: The function returns another array that contains the intersection of all the input arrays. If no element matches then, a NULL array is returned.
Input : $array1 = ("1" => "shyam", "2" => "rishav", "3" => "gaurav"); $array2 = ("1" => "shyam", "2" => "rishi", "3" => "rishav"); $array3 = ("1" => "shyam", "2" => "rishav", "3" => "ravi"); Output : Array (  => shyam )
In the below program, we have used array_intersect_assoc() to find the intersection between arrays. Let’s look closer at the outputs of this and array_intersect() function.
Array (  => shyam )
In the above program we have used the array_intersect_assoc() to find the intersection of the arrays. In the below program we will use the array_intersect() function to do the same. Give close attention to the outputs of both the programs. The first one returns only those elements which are strictly similar, both by values and keys, unlike array_intersect().
Array (  => shyam  => rishav )
This article is attributed to GeeksforGeeks.org