The array_uintersect_assoc()
function is used to compare the key names and key values of two (or more) arrays and returns the intersection (match).
Note: This function uses built-in functions to compare key names, and uses user-defined functions to compare key values!
The function compares the key names and key values of two (or more) arrays and returns an intersection array that includes all key names and key values in the array being compared ( array1 ) and also in any other parameter array ( array2 or array3 , etc.).
Note that the difference from array_uintersect()
is that the key names should also be compared. Data (key value) are compared using callback functions.
Compare the key names and key values of two arrays (using built-in functions to compare key names, using user-defined functions to compare key values), and return the intersection:
<?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 ) ; ?>
Try it yourself