HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

array_udiff_assoc

Description

The array_udiff_assoc of Array for PHP computes the difference of arrays with additional index check, compares data by a callback function.

Syntax

array_udiff_assoc(
    array $array,
    array ...$arrays,
    callable $value_compare_func
): array

Parameters

array

The array to compare from.

arrays

The arrays to compare against.

value_compare_func

The comparison function must 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.

callback(
    mixed $a,
    mixed $b
): int

Return

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

NOTE: The keys are used in the comparison unlike array_diff() and array_udiff(). The comparison of arrays' data is performed by using an user-supplied callback. In this aspect the behaviour is opposite to the behaviour of array_diff_assoc() which uses internal function for comparison.

Examples

1 · array arrays · one · value_compare_func

<?

function mycallback($mya, $myb)
{
    return $mya <=> $myb;
}

$array =
[
    "a" => 0,
    "b" => 1,
    "c" => 2,
    "d" => 3
];
$arrays =
[
    "a" => 0,
    "b" => 4,
    "e" => 2,
    "f" => 5
];
$value_compare_func = "mycallback";

$return = array_udiff_assoc($array, $arrays, $value_compare_func);

print_r($return);
Array
(
    [b] => 1
    [c] => 2
    [d] => 3
)

2 · array arrays · multiple · value_compare_func

<?

function mycallback($mya, $myb)
{
    return $mya <=> $myb;
}

$array =
[
    "a" => 0,
    "b" => 1,
    "c" => 2,
    "d" => 3
];
$arrays1 =
[
    "a" => 0,
    "b" => 4,
    "e" => 2,
    "f" => 5
];
$arrays2 =
[
    "a" => 0,
    "b" => 4,
    "e" => 2,
    "f" => 5
];
$value_compare_func = "mycallback";

$return = array_udiff_assoc($array, $arrays1, $arrays2, $value_compare_func);

print_r($return);
Array
(
    [b] => 1
    [c] => 2
    [d] => 3
)