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

array_uintersect_uassoc() function in PHP

PHPz
Release: 2023-08-27 14:46:01
forward
697 people have browsed it

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)
Copy after login

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);
?>
Copy after login

Output

The following is the output-

ArrayArray
(
[a] => laptop
[b] => keyboard
)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template