array_uintersect_uassoc() function in PHP


The array_uintersect_unassoc() function compares array keys and array values in user-made functions, and returns an array

Syntax

array_uintersect_uassoc(arr1, arr2, arr3, … , compare_func1, compare_func2)

Parameters

  • arr1 − The first array to compare from.

  • arr2 − The second array to be compared with.

  • arr3 − More arrays to compare.

  • compare_func1 − The comparison function that compares the array keys. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.

  • compare_func2 − The comparison function that compares the array values. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.

Return

The array_uintersect_uassoc() function returns an array containing all the values of the first array that are not present in any of the other parameters.

Example

The following is an example −

 Live Demo

<?php
function compare_func_key($a, $b) {
   if ($a === $b) {
      return 0;
   }
   return ($a > $b)? 1:-1;
}
function compare_func_val($a, $b) {
   if ($a === $b) {
      return 0;
   }
   return ($a > $b)? 1:-1;
}
$arr1 = array("a" => "laptop", "b" => "keyboard", "c" => "mouse");
$arr2 = array("a" => "laptop", "b" => "keyboard", "c" => "headphone");
$res = array_uintersect_uassoc($arr1, $arr2, "compare_func_key", "compare_func_val");
print_r($res);
?>

Output

The following is the output −

ArrayArray
(
[a] => laptop
[b] => keyboard
)

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 24-Jun-2020

15 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements