PHP array_udiff_uassoc() Function

array_udiff_uassoc() Function used for Compare the keys and values of two arrays and return the differences.

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 not present in any 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_udiff_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"=>"Samuel","b"=>"Cooper","c"=>"Alex");
$array2=array("a"=>"Samuel","b"=>"Cooper","c"=>"James");

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

Output

Array ( [c] => Alex ) 

Leave a Reply

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