PHP array_udiff_uassoc function

Last Updated: February 15, 2022

array_udiff_uassoc — Compute the difference of arrays using keys and values. Use call back functions to compare values and keys

Syntax

 array_udiff_uassoc(
    array $array,
    array ...$arrays,
    callable $value_compare_func,
    callable $key_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.

key_compare_func

callback function for keys

Return Value

returns an array containing all the values from array that are not present in any of the other arguments

Example

function myKey_function($a,$b)
{
    if ($a===$b)
    {
        return 0;
    }
    return ($a>$b)?1:-1;
}

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_uassoc($a1,$a2,"myValue_function","myKey_function");
print_r($result);

Output

Array ( [b] => two [c] => three ) 
Test