PHP array_udiff_assoc function
Last Updated: February 15, 2022
array_udiff_assoc — Compute the difference of arrays using keys and values. Use call back function to compare values
Syntax
array_udiff_assoc(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 |
Return Value
array_udiff_assoc() returns an array containing all the values from array
that are not present in any of the other arguments
Example
function myfunction($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_assoc($a1,$a2,"myfunction");
print_r($result);
Output
Array ( [b] => two [c] => three )