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 )
- How to get the function name inside a function in PHP ?
- PHP | Ds\Set first() Function
- PHP | Ds\Set last() Function
- PHP | pow( ) Function
- PHP | next() Function
- p5.js | nfs() Function
- D3.js | d3.set.add() Function
- PHP | each() Function
- p5.js | box() Function
- p5.js | nfc() function
- p5.js | nf() Function
- D3.js | d3.map.set() Function
- PHP | Ds\Set add() Function
- p5.js | nfp() Function
- D3.js | d3.hsl() Function
- PHP | end() Function
- PHP | max( ) Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.