Home >>PHP Array Functions >PHP array_udiff_uassoc( ) Function

PHP array_udiff_uassoc( ) Function

PHP array_udiff_uassoc( ) Function

PHP array_udiff_uassoc( ) function is used to get the difference between two or more given input arrays. It compares two or more arrays according to their keys and values using two user-made functions and returns an array containing the elements that are present in the first array but not in the other given arrays.

Syntax:

array_udiff_uassoc(array1,array2,array3, ...,func_key,func_value);

Parameter Values

Parameter Description
array1 This is a requiredparameter.This parameter defines the array to compare from.
array2 This is a requiredparameter.This parameter definesan array to compare against.
array3,... This is an optionalparameter.This parameter definesmore arrays to compare against.
func_key This is a requiredparameter.This parameter definesthe name of the user-defined function that compares the array keys.
func_value This is a requiredparameter.This parameter definesthe name of the user-defined function that compares the array values.

Here is an example of array_udiff_uassoc() function in PHP:

<html>
<body>
<pre>
<?php
function function_key($a,$b)
{
if ($a===$b)
  {
  return 0;
  }
  return ($a>$b)?1:-1;
}
function function_value($a,$b)
{
if ($a===$b)
  {
  return 0;
  }
  return ($a>$b)?1:-1;
}
$x=array("a"=>"PHP","b"=>"PHPTPOINT","c"=>"Python","d"=>"Java","e"=>"NodeJS");
$y=array("a"=>"PHP","b"=>"Java","d"=>"Python","e"=>"NodeJS");
$result=array_udiff_uassoc($x,$y,"function_key","function_value");
print_r($result);
?>
</pre>
</body>
</html>
Output:
Array
(
    [b] => PHPTPOINT
    [c] => Python
    [d] => Java
)

No Sidebar ads