Definition and usage
array_diff_ukey() returns an array containing the values of all keys that appear in array1 but do not appear in any other parameter array. Note that the relationship remains unchanged. Unlike array_diff(), the comparison is based on key names rather than values.
This comparison is performed via a user-supplied callback function. If the first argument is considered less than, equal to, or greater than the second argument, an integer less than zero, equal to zero, or greater than zero must be returned, respectively.
Grammar
array_diff_ukey(array1,array2,array3...,function)
Parameters
Description
array1 required. The first array to compare with other arrays.
array2 required. The array to compare to the first array.
array3 is optional. The array to compare to the first array. There can be multiple.
function required. The name of the user-defined function.
Example 1
$v2) { return 1; } else { return -1 ; } } $a1=array(0=>"Dog",1=>"Cat",2=>"Horse"); $a2=array(3=>"Rat",1=> "Bird",5=>"Monkey"); print_r(array_diff_ukey($a1,$a2,"myfunction")); ?>
Output:
Array ( [0] => Dog [2] => Horse )
Example 2
How to allocate multiple arrays to this function:
$v2) { return 1; } else { return -1 ; } } $a1=array(0=>"Dog",1=>"Cat",2=>"Horse"); $a2=array(3=>"Rat",1=> "Bird",5=>"Monkey"); $a3=array(6=>"Dog",7=>"Donkey",0=>"Horse"); print_r(array_diff_ukey($a1, $a2,$a3,"myfunction")); ?>
Output:
Array ( [2] => Horse )