PHP array_intersect_ukey() 函数
PHP 教程
· 2019-01-22 09:27:09
实例
比较两个数组的键名(使用用户自定义函数比较键名),并返回交集:
<?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"=>"blue","b"=>"black","e"=>"blue");
$result=array_intersect_ukey($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"=>"blue","b"=>"black","e"=>"blue");
$result=array_intersect_ukey($a1,$a2,"myfunction");
print_r($result);
?>
定义和用法
array_intersect_ukey() 函数用于比较两个(或更多个)数组的键名 ,并返回交集。
注释:该函数使用用户自定义函数比较键名!
该函数比较两个(或更多个)数组的键名,并返回一个交集数组,该数组包括了所有在被比较的数组(array1)中,同时也在任何其他参数数组(array2 或 array3 等等)中的键名。
语法
array_intersect_ukey(array1,array2,array3...,myfunction)
| 参数 | 描述 |
|---|---|
| array1 | 必需。与其他数组进行比较的第一个数组。 |
| array2 | 必需。与第一个数组进行比较的数组。 |
| array3,... | 可选。与第一个数组进行比较的其他数组。 |
| myfunction | 必需。一个定义了可调用比较函数的字符串。如果第一个参数 <, =, > 第二个参数,相应地比较函数必须返回一个 <, =, > 0 的整数。 |
技术细节
| 返回值: | 返回一个交集数组,该数组包括了所有在被比较的数组(array1)中,同时也在任何其他参数数组(array2 或 array3 等等)中的键名。 |
|---|---|
| PHP 版本: | 5.1.0+ |
更多实例
实例 1
比较三个数组的键名(使用用户自定义函数比较键名),并返回交集:
<?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"=>"black","b"=>"yellow","d"=>"brown");
$a3=array("e"=>"purple","f"=>"white","a"=>"gold");
$result=array_intersect_ukey($a1,$a2,$a3,"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"=>"black","b"=>"yellow","d"=>"brown");
$a3=array("e"=>"purple","f"=>"white","a"=>"gold");
$result=array_intersect_ukey($a1,$a2,$a3,"myfunction");
print_r($result);
?>
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
Probability and Computing
Michael Mitzenmacher、Eli Upfal / Cambridge University Press / 2005-01-31 / USD 66.00
Assuming only an elementary background in discrete mathematics, this textbook is an excellent introduction to the probabilistic techniques and paradigms used in the development of probabilistic algori......一起来看看 《Probability and Computing》 这本书的介绍吧!