PHP array_uintersect_uassoc () function
Examples
Compare two arrays of keys and values (user-defined function for comparison), and returns the intersection:
<?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);
?>
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);
?>
Running instance »
Definition and Usage
array_uintersect_uassoc () function is used to compare two (or more) of the array keys and values, and returns the intersection.
Note: This function uses two user-defined function for comparison; first comparison function keys, and the second function that compares keys!
This function compares two (or more) of the array keys and values, and returns an intersection of the array includes all the compared array (array1), and also in any other parameter array (array2 or array3 etc.) the key names and values.
grammar
array_uintersect_uassoc( array1,array2,array3...,myfunction_key,myfunction_value )
参数 | 描述 |
---|---|
array1 | 必需。与其他数组进行比较的第一个数组。 |
array2 | 必需。与第一个数组进行比较的数组。 |
array3,... | 可选。与第一个数组进行比较的其他数组。 |
myfunction_key | 必需。用于比较数组键名的用户自定义函数的名称。 一个定义了可调用比较函数的字符串。如果第一个参数 <, =, > 第二个参数,相应地比较函数必须返回一个 <, =, > 0 的整数。 |
myfunction_value | 必需。用于比较数组键值的用户自定义函数的名称。 一个定义了可调用比较函数的字符串。如果第一个参数 <, =, > 第二个参数,相应地比较函数必须返回一个 <, =, > 0 的整数。 |
technical details
return value: | It returns an intersection array includes all the compared array (array1), and also in any other parameter array (array2 or array3 etc.) in key names and values. |
---|---|
PHP version: | 5+ |
Complete PHP Array Reference