Home  >  Article  >  Backend Development  >  array_uintersect_uassoc() function in PHP

array_uintersect_uassoc() function in PHP

PHPz
PHPzforward
2023-08-27 14:45:04648browse

array_uintersect_uassoc() function in PHP

array_uintersect_unassoc() function compares array keys and array values ​​in user-defined functions and returns an array

Syntax

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

Parameters

  • arr1 - The first array to be compared.

  • arr2 - The second array to be compared.

  • arr3 - More arrays to compare.

  • compare_func1 - Comparison function used to compare array keys. If the first argument is considered less than, equal to, or greater than the second argument, an integer less than, equal to, or greater than zero must be returned.

  • compare_func2 - Comparison function used to compare array values. If the first argument is considered less than, equal to, or greater than the second argument, an integer less than, equal to, or greater than zero must be returned.

Return value

array_uintersect_uassoc() function returns an array containing all values ​​in the first array that do not appear in 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
)

The above is the detailed content of array_uintersect_uassoc() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete