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

PHP array_uintersect_uassoc() Function

PHP array_uintersect_uassoc() Function

PHP array_uintersect_uassoc() function is used to compare the keys and values of two or more given input arrays by using two user-defined functions and returns the matches.

Syntax:

array_uintersect_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_uintersect_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"=>"1","b"=>"2","c"=>"3","d"=>"4","e"=>"5");
$y=array("a"=>"1","b"=>"2","c"=>"3","d"=>"5","e"=>6);
$result=array_uintersect_uassoc($x,$y,"function_key","function_value");
print_r($result);
?>
</pre>
</body>
</html>
Output:
Array
(
    [a] => 1
    [b] => 2
    [c] => 3
)

Example 2:

<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"=>"Abhi","b"=>"Jerry","c"=>"Noida","d"=>"Python");
$y=array("a"=>"Abhi","c"=>"Noida","d"=>"PHP");
$result=array_uintersect_uassoc($x,$y,"function_key","function_value");
print_r($result);
?>
</pre>
</body>
</html>
Output:
Array
(
    [a] => Abhi
    [c] => Noida
)

No Sidebar ads