The array_udiff() function compares the values of two or more, and returns the differences.
Note: This function uses a user-defined function to compare the values!
Returns an array containing the entries from array1 that are not present in any of the other arrays
Parameter | Is Required | Description |
---|---|---|
array1 | Required. | Array to compare from |
array2 | Required. | Array to compare against |
array3,… | Optional. | More arrays to compare against |
myfunction | Required. | A string that define a callable comparison function. |
Syntax
array_udiff(array1,array2,array3...,myfunction)
Example
function myfunctiondemo($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}
$array1=array("a"=>"Cooper","b"=>"Samuel","c"=>"Lachlan");
$array2=array("a"=>"Lachlan","b"=>"James","e"=>"Lachlan");
$result=array_udiff($array1,$array2,"myfunctiondemo");
print_r($result);
Output
Array ( [a] => Cooper [b] => Samuel )