PHP array_uintersect_uassoc function

Last Updated: February 15, 2022

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

Syntax

 array_uintersect_uassoc(
    array $array1,
    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 of array1 that are present in all the 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"=>"two","c"=>"four");

$result=array_uintersect_uassoc($a1,$a2,"myValue_function","myKey_function");
print_r($result);

Output

Array ( [a] => one [b] => two ) 
Test