PHP array_uintersect_uassoc() 函数

PHP 教程 · 2019-01-22 15:59:33

实例

比较两个数组的键名和键值(使用用户自定义函数进行比较),并返回交集:

<?php
function myfunction_key($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}

function myfunction_value($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}

$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("a"=>"red","b"=>"green","c"=>"green");

$result=array_uintersect_uassoc($a1,$a2,"myfunction_key","myfunction_value");
print_r($result);
?>

定义和用法

array_uintersect_uassoc() 函数用于比较两个(或更多个)数组的键名和键值,并返回交集。

注释:该函数使用两个用户自定义函数进行比较;第一个函数比较键名,第二个函数比较键值!

该函数比较两个(或更多个)数组的键名和键值,并返回一个交集数组,该数组包括了所有在被比较的数组(array1)中,同时也在任何其他参数数组(array2array3 等等)中的键名和键值。

语法

array_uintersect_uassoc(array1,array2,array3...,myfunction_key,myfunction_value)

参数 描述
array1 必需。与其他数组进行比较的第一个数组。
array2 必需。与第一个数组进行比较的数组。
array3,... 可选。与第一个数组进行比较的其他数组。
myfunction_key 必需。用于比较数组键名的用户自定义函数的名称。
一个定义了可调用比较函数的字符串。如果第一个参数 <, =, > 第二个参数,相应地比较函数必须返回一个 <, =, > 0 的整数。
myfunction_value 必需。用于比较数组键值的用户自定义函数的名称。
一个定义了可调用比较函数的字符串。如果第一个参数 <, =, > 第二个参数,相应地比较函数必须返回一个 <, =, > 0 的整数。

技术细节

返回值: 返回一个交集数组,该数组包括了所有在被比较的数组(array1)中,同时也在任何其他参数数组(array2array3 等等)中的键名和键值。
PHP 版本: 5+

点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html

查看所有标签

Data Structures and Algorithms in Python

Data Structures and Algorithms in Python

Michael T. Goodrich、Roberto Tamassia、Michael H. Goldwasser / John Wiley & Sons / 2013-7-5 / GBP 121.23

Based on the authors' market leading data structures books in Java and C++, this book offers a comprehensive, definitive introduction to data structures in Python by authoritative authors. Data Struct......一起来看看 《Data Structures and Algorithms in Python》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

html转js在线工具
html转js在线工具

html转js在线工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具