array_uintersect_uassoc()
function compares the key names and key values of two (or more) arrays and returns the intersection.
Note: This function is compared using two user-defined functions; the first function compares the key names, and the second function compares the 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. Key values and key names (indexes) are compared using callback functions.
Compare the key names and key values of two arrays (compare with user-defined functions) and return the intersection (match):
<?php function myfunction_key ( $a , $b ) { if ( $a === $b ) { return 0 ; } return ( $a > $b ) ? 1 : - 1 ; } function myfunction_value ( $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" => "green" , "c" => "green" ) ; $result = array_uintersect_uassoc ( $a1 , $a2 , "myfunction_key" , "myfunction_value" ) ; print_r ( $result ) ; ?>
Try it yourself