Wednesday, 24 September 2014

PHP: array_intersect_uassoc in PHP

array_intersect_uassoc() function is used to compare two or more arrays with an additional user defined function.
It returns result array containing the keys that are not present in other arrays subject to user define function allows.

Syntax:   array_intersect_uassoc(array1,array2,array3...,function)

Parameters Description:
array1 : Required. The first array is the array that the others will be compared with
array2 : Required. An array to be compared with the first array
array3 : Optional. An array to be compared with the first array

function : Required. The name of the user-made function

Example:

<?php
function myfunc($par1,$par2)
{
if($par1===$par2)
{
 return 0;
}
if($par1>$par2)
{
 return 1;
}
else
{
 return -1;
}
}
$daysarr1 = array(0=>"Sunday",1=>"Monday",3=>"Tuesday");
$daysarr2 = array(0=>"Sunday",1=>"Monday",5=>"Tuesday");
$daysarr3 = array(6=>"Wednesday",0=>"Sunday",5=>"Tuesday");
print_r( array_intersect_uassoc($daysarr1,$daysarr2,$daysarr3,"myfunc") );
?>

O/P:


Array (
        [0] => Sunday
       )

0 comments:

Post a Comment