Compare the keys and values of two arrays using a built-in function for key comparison and a user-defined function for value comparison, and return the matching entries.
<?php function myfunction($a,$b) { if ($a===$b) { return 0; } return ($a>$b)?1:-1; } $a1=array(“a”=>“red”,“b”=>“green”,“c”=>“blue”); $a2=array(“a”=>“red”,“b”=>“blue”,“c”=>“green”); $result=array_uintersect_assoc($a1,$a2,“myfunction”); print_r($result); ?> |
The array_uintersect_assoc()
function compares the keys and values of two or more arrays and returns the matching entries.
Note: It uses a built-in function for key comparison and a user-defined function for value comparison.
This function compares both the keys and values of the arrays and returns an array containing entries from the first array that are present in the second, third, and any additional arrays.
array_uintersect_assoc(array1, array2, array3, …, myfunction) |
Parameter |
Description |
array1 |
Required. The array to be used for comparison. |
array2 |
Required. An array to compare with. |
array3,… |
Optional. Additional arrays to compare with. |
myfunction |
Required. A string specifying a callable comparison function. The function must return an integer less than, equal to, or greater than 0, depending on whether the first argument is less than, equal to, or greater than the second argument. |
Return Value: |
Returns an array with entries from array1 that are found in all the other arrays. |
PHP Version: |
5+ |