PHP array_uintersect function

Last Updated: February 15, 2022

array_uintersect — Compute the intersection of arrays using values. Use call back functions to compare values

Syntax

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

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

Output

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