PHP array_uintersect() Function

What is array_uintersect() Function?

Explanation

The "array_uintersect()" function computes the intersection of arrays, compares elements by a callback function.

Syntax:


array_uintersect(array1,array2,array3...,function)

In the above syntax "array1" and "array2" are compared for values in "function" ,then returns an array of elements of "array1".

Example :


<?php
function funct1($x1,$x2)
{
if ($x1===$x2)
{
return 0;
}
if ($x1 > $x2) return 1;
{
return -1;
}
return 1;
}
}
$a=array("a"=>"Orange","b"=>"Guava","c"=>"Apple");
$b=array(1 =>"Orange",2 =>"Guava", 3 =>"Cherry");
print_r(array_uintersect($a,$b,"funct1"));
?>
Result :

Array ( [a]=> Orange [b]=> Guava );

In the above example both arrays are compared for values in "funct1", the intersecting values of "$a" is returned in an array.

PHP Topics


Ask Questions

Ask Question