【函数功能】
该函数用自定义函数比较两个(或更多个)数组的键名键值 ,并返回差集。
【函数语法】
array_udiff_assoc (array $array1, array $array2, array $_ = null, $value_compare_func)
【参数说明】
$array1:必需,与其他数组进行比较的第一个数组。
$array2:必需,与第一个数组进行比较的数组。
$_,...:可选,与第一个数组进行比较的其他数组。
$value_compare_func:自定义函数
【演示程序】
<?php
/**
* array_udiff_assoc (array $array1, array $array2, array $_ = null, $value_compare_func)
* **/
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","e"=>"black","f"=>"blue");
$result=array_udiff_assoc($a1,$a2,"myfunction");
print_r($result);
?>
【输出结果】
Array ( [b] => green [c] => blue )
【特别注意】
1.可用一个或任意多个数组与第一个数组进行比较。
2.该函数将键值用于比较,只有当键名键值都相同时才会被剔除。
3.PHP 版本:5.0+。
【原版定义】
/**
* Computes the difference of arrays with additional index check, compares data by a callback function
* @link http://www.php.net/manual/en/function.array-udiff-assoc.php
* @param array1 array <p>
* The first array.
* </p>
* @param array2 array <p>
* The second array.
* </p>
* @param _ array[optional]
* @param value_compare_func callable <p>
* The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
* </p>
* &callback.cmp;
* @return array array_udiff_assoc returns an array
* containing all the values from array1
* that are not present in any of the other arguments.
* Note that the keys are used in the comparison unlike
* array_diff and array_udiff.
* The comparison of arrays' data is performed by using an user-supplied
* callback. In this aspect the behaviour is opposite to the behaviour of
* array_diff_assoc which uses internal function for
* comparison.
*/
转载请注明出处:php1234.cn ,原文地址:http://www.php1234.cn/a/functions/2017/0315/200.html