PHP - Function array_diff_ukey()



array_diff_ukey ( $array1, $array2 [, $array3...,callback $key_compare_func] );

Definition and Usage

Compares the keys from array1 against the keys from array2 and returns the difference. This function is like array_diff() except the comparison is done on the keys instead of the values.

Unlike array_diff_key() an user supplied callback function is used for the indices comparision, not internal function.


array1Required. The first array is the array that the others will be compared with.
array2Required. An array to be compared with the first array
array3Optional. An array to be compared with the first array
key_compare_funcRequired. callback function to use. The callback function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.

Return Values

Returns an array containing all the entries from array1 that are not present in any of the other arrays.


Try out following example:

function key_compare_func($v1,$v2) 
if ($v1===$v2)
	return 0;
if ($v1>$v2)
	return 1;
	return -1;
$array1 = array(0=>"banana", 1=>"orange", 2=>"grapes");
$array2 = array(3=>"apple",1=>"apricot", 5=>"mango");

This will produce following result:

Array ( [0]=>banana [2]=>grapes )