PHP array_diff_ukey() function
Last Updated: February 11, 2022
array_diff_ukey()
: Compare the keys of two arrays (using a user-defined key comparison function), and return the differences.
Syntax
array_diff_ukey(array $array, array ...$arrays, callable $key_compare_func): array
Parameters
Parameter | Description |
array | Required. The array to compare from |
arrays | Required. arrays to compare against |
key_compare_func |
Required. Key comaparison function will return integer less than, equal to, or greater than zero . First argument is compared agaist the second argument |
Return Value
Returns an array containing all the entries from array
that are not present in any of the other arrays.
Example
function myfunction($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}
$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("d"=>"red","b"=>"green","e"=>"blue");
$result=array_diff_ukey($a1,$a2,"myfunction");
print_r($result);
?>
Output
Array ( [a] => red [c] => blue )