PHP Tutorial - PHP array_diff_uassoc() function


The array_diff_uassoc() function compares the arrays with a user-defined function and returns the differences.


PHP array_diff_uassoc() function has the following syntax.



ParameterIs RequiredDescription
array1Required.Array to compare from
array2Required.Array to compare against
array3,...Optional.More arrays to compare against
myfunctionRequired.A string that define a callable comparison function.

The comparison function must return an integer <, =, or > than 0 if the first argument is less than, equals, or greater than the second argument


Compare the keys and values of two arrays use a user-defined function to compare the keys, and return the differences:

<?php//from w w  w.  j a v a 2s .c o m
function myfunction($a,$b){
    if ($a===$b){
      return 0;
    return ($a>$b)?1:-1;



The code above generates the following result.