PHP array_uintersect() function || PHP Arrays
×


array_uintersect() function in php

1925

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:




Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments