PHP array_udiff_uassoc() function

PHP array_splice() function
PHP array_uintersect() function

The array_udiff_uassoc function works like the array_udiff_assoc function but uses two user-defined functions for the comparison of keys and values.

This function compares keys and values of the first array with the following arrays and returns an array that contains the values that are present in array 1 but not in the rest of the arrays.

Once the user-defined function compares the keys and the second compares the values.

What is the syntax of the array_udiff_uassoc function in PHP?

array_udiff_uassoc(array1, array2, array3, ..., myfunc_key, myfunc_value)
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 keys functionUser-defined function to compare the keys of arrays. The function must return an integer <, = or > than 0 if the first argument is <, + or > than the second argument.
user-defined values function User-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_udiff_uassoc

Example of array_udiff_uassoc function

Example 1. Return the difference of arrays using array_udiff_uassoc functions that use two user-defined functions.

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

function my_value_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"=>"R","b"=>"G","c"=>"G");

$result=array_udiff_uassoc($array_1,$array_2,"my_value_function","my_key_function");
print_r($result);
?>
PHP array_splice() function
PHP array_uintersect() function
en English
X
Scroll to Top