PHP array_uintersect_assoc() 函数
PHP 教程
· 2019-01-22 15:43:56
实例
比较两个数组的键名和键值(使用内建函数比较键名,使用用户自定义函数比较键值),并返回交集:
<?php
function myfunction($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"=>"blue","c"=>"green");
$result=array_uintersect_assoc($a1,$a2,"myfunction");
print_r($result);
?>
function myfunction($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"=>"blue","c"=>"green");
$result=array_uintersect_assoc($a1,$a2,"myfunction");
print_r($result);
?>
定义和用法
array_uintersect_assoc() 函数用于比较两个(或更多个)数组的键名和键值 ,并返回交集。
注释:该函数使用内建函数比较键名,使用用户自定义函数比较键值!
该函数比较两个(或更多个)数组的键名和键值,并返回一个交集数组,该数组包括了所有在被比较的数组(array1)中,同时也在任何其他参数数组(array2 或 array3 等等)中的键名和键值。
语法
array_uintersect_assoc(array1,array2,array3...,myfunction)
| 参数 | 描述 |
|---|---|
| array1 | 必需。与其他数组进行比较的第一个数组。 |
| array2 | 必需。与第一个数组进行比较的数组。 |
| array3,... | 可选。与第一个数组进行比较的其他数组。 |
| myfunction | 必需。一个定义了可调用比较函数的字符串。如果第一个参数 <, =, > 第二个参数,相应地比较函数必须返回一个 <, =, > 0 的整数。 |
技术细节
| 返回值: | 返回一个交集数组,该数组包括了所有在被比较的数组(array1)中,同时也在任何其他参数数组(array2 或 array3 等等)中的键值。 |
|---|---|
| PHP 版本: | 5+ |
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
Data Structures and Algorithm Analysis in Java
Mark A. Weiss / Pearson / 2006-3-3 / USD 143.00
As the speed and power of computers increases, so does the need for effective programming and algorithm analysis. By approaching these skills in tandem, Mark Allen Weiss teaches readers to develop wel......一起来看看 《Data Structures and Algorithm Analysis in Java》 这本书的介绍吧!
html转js在线工具
html转js在线工具
UNIX 时间戳转换
UNIX 时间戳转换