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

array_entersect_ukey() function in PHP

WBOY
WBOYforward
2023-09-06 09:37:031131browse

array_entersect_ukey() function in PHP

array_intersect_ukey() function compares the keys of an array, checks with additional user-defined functions, and returns matching results. This function returns an array containing the entries in the first array that are present in all other arrays.

Syntax

array_intersect_ukey(arr1, arr2, arr3, arr4, …, compare_func)

Parameters

  • arr1 - The array to compare. Required.

  • arr2 - The array to compare. Required.

  • arr3 -You can add more arrays to compare. Optional.

  • arr4 - You can add more arrays to compare. Optional.

  • compare_func - If the first argument is considered , = or > respectively instead of the second.

Return

array_intersect_ukey() function returns an array containing the entries present in the first array in all other arrays.

Example

The following is an example of comparing keys.

Real-time demonstration

<?php
function check($a,$b) {
   if ($a===$b) {
      return 0;
   }
   return ($a>$b)?1:-1;
}
$arr1 = array("a"=>"one","b"=>"two","c"=>"three");
$arr2 = array("a"=>"one","b"=>"two");
$result = array_intersect_ukey($arr1,$arr2,"check");
print_r($result);
?>

Output

Array
(
[a] => one
[b] => two
)

The above is the detailed content of array_entersect_ukey() 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