PHP array_uintersect() function

PHP array_udiff_uassoc() function
PHP array_uintersect_assoc() function

The array_uintersect function compares values of two or more arrays based on a user-defined values comparison function and returns the matching results.

The user-defined function takes the values only and passes them through the user-defined logic.

What is the syntax of the array_uintersect function in PHP?

array_uintersect(array1, array2, array3, ..., myfunction)
ParametersDetails
array1The first array to compare with other arrays – required
array2Second array to make a comparison against- required
array3, ...Further arrays to compare against – optional
user-defined functionUser-defined function to compare the values of arrays. The function must return an integer <, = or > than 0 if the first argument is <, + or > than the second argument.
array_uintersect function in PHP

Examples of array_uintersect function

Example 1. Compare the values of two arrays using a user-defined function.

<?php
function my_function($x,$y)
{
if ($x==$y)
  {
  return 0;
  }
  return ($x>$y)?1:-1;
}

$array_1=array("a"=>"R","b"=>"G","c"=>"B");
$array_2=array("a"=>"B","b"=>"Bl","e"=>"Bu");

$result=array_uintersect($array_1,$array_2,"my_function");
print_r($result);
?>

Example 2. Compare the values of three arrays using a user-defined function and return the matches.

<?php
function my_function($x,$y)
{
if ($x==$y)
  {
  return 0;
  }
  return ($x>$y)?1:-1;
}

$array_1=array("a"=>"R","b"=>"G","c"=>"B");
$array_2=array("a"=>"B","b"=>"Bl","e"=>"Bu");
$array_3=array("a"=>"G","b"=>"R","e"=>"Bl");

$result=array_uintersect($array_1,$array_2$array_3,,"my_function");
print_r($result);
?>

PHP array_udiff_uassoc() function
PHP array_uintersect_assoc() function
en English
X
Scroll to Top