array_uintersect() function in php
Last Updated by Pooja Chikara
0 2419
PHP array_uintersect() function is used to return the intersection or match values of two or more arrays by comparing the values with the help of a user-defined function. It is an inbuilt function of PHP.
Syntax:
array_uintersect($array1,$array2,... ...,$arrayN,user_function);
Here,
- $array1 is a PHP array which matched values returned by this function.
- $array2,$array3 and $arrayN are also PHP arrays which values is compared with the values of $array1.
- user_function is a user defined comparison function which used to calculate the common values of arrays by comparing the values.
Example 1:
<?php
function user_function($x,$y)
{
if ($x===$y)
{
return 0;
}
return ($x>$y)?1:-1;
}
$arr1=array("FRUIT1"=>"apple","FRUIT2"=>"guava","FRUIT3"=>"orange","FRUIT4"=>"fig");
$arr2=array("FRUIT1"=>"apple","FRUIT2"=>"fig","FRUIT3"=>"guava","FRUIT4"=>"guava");
$result=array_uintersect($arr1,$arr2,"user_function");
echo "<pre>";
print_r($result);
?>Output:

Share:

Comments
Waiting for your comments