比较值两个数组的比较(使用用户定义的函数来比较值)并返回差异:
<?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_udiff($a1,$a2,"myfunction");
print_r($result);
?>
亲自试一试 »
array_udiff() 函数比较值两个或多个数组,并返回差异。
笔记:该函数使用用户定义的函数来比较值!
此函数比较两个(或多个)数组的值,并返回一个包含以下条目的数组数组1不存在于数组2或者数组3, ETC。
array_udiff(
array1, array2, array3, ..., myfunction)
Parameter | Description |
---|---|
array1 | Required. The array to compare from |
array2 | Required. An array to compare against |
array3,... | Optional. More arrays to compare against |
myfunction | Required. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument |
返回值: | 返回一个包含条目的数组数组1不存在于任何其他数组中 |
---|---|
PHP 版本: | 5.1.0+ |
比较值三个数组(使用用户定义的函数来比较值),并返回差异:
<?php
function myfunction($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}
$a1=array("a"=>"red","b"=>"green","c"=>"blue","yellow");
$a2=array("A"=>"red","b"=>"GREEN","yellow","black");
$a3=array("a"=>"green","b"=>"red","yellow","black");
$result=array_udiff($a1,$a2,$a3,"myfunction");
print_r($result);
?>
亲自试一试 »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!