PHP array_udiff function
Last Updated: February 15, 2022
array_udiff — Compute the difference of arrays Use callback functions to compare values
Syntax
array_udiff(array $array, array ...$arrays, callable $value_compare_func): array
Supports (PHP 5, PHP 7, PHP 8)
Parameters
Parameter | Description |
array | first array |
arrays | arrays to compare against |
value_compare_func |
callback function for values 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 Value
returns an array containing all the values from array
that are not present in any of the other arguments
Example
function myValue_function($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}
$a1=array("a"=>"one","b"=>"two","c"=>"three");
$a2=array("a"=>"one","b"=>"three","c"=>"four");
$result=array_udiff($a1,$a2,"myValue_function");
print_r($result);
Output
Array ( [b] => two )