PHP array_uintersect_uassoc() Function

The array_uintersect_uassoc() function compares the keys and values of two or more arrays, and returns the matches.

Note: This function uses two user-defined functions for comparison; the key is used in the first function and the value is used in the second!

Returns an array containing the entries from array1 that are present in all of the other arrays

Parameter 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
function1 Required. The name of the user-made function that compares the array keys
function2 Required. The name of the user-made function that compares the array values

Syntax

 array_uintersect_uassoc(array1,array2,array3...,myfunction_key,myfunction_value) 

Example

function myfunction_key($a,$b)
{
if ($a===$b)
  {
  return 0;
  }
  return ($a>$b)?1:-1;
}

function myfunction_value($a,$b)
{
if ($a===$b)
  {
  return 0;
  }
  return ($a>$b)?1:-1;
}

$array1=array("a"=>"Cooper","b"=>"Samuel","c"=>"Lachlan");
$array2=array("a"=>"Lachlan","c"=>"Lachlan","e"=>"Lachlan");

$result=array_uintersect_uassoc($array1,$array2,"myfunction_key","myfunction_value");
print_r($result);

Example

Array ( [c] => Lachlan ) 

Leave a Reply

Your email address will not be published. Required fields are marked *