PHP array_uintersect_assoc()Functions
Complete PHP Array Reference Manual
Examples
Compare the two arrays'key names and key values(use built-in function to compare key names, use user-defined function to compare key values), and return the intersection:
<?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);
?>
Run Example »
Definition and Usage
The array_uintersect_assoc() function is used to compare thekey names and key values, and return the intersection.
Note:This function uses built-in functions to compare key names, and user-defined functions to compare key values!
This function compares the key names and key values of two (or more) arrays, and returns an intersection array that includes all in the compared array (array1), and also in any other parameter array (array2orarray3etc.) key names and key values.
Syntax
array_uintersect_assoc(array1,array2,array3...,myfunction)
| Parameters | Description |
|---|---|
| array1 | Required. The first array to compare with other arrays. |
| array2 | Required. The array to compare with the first array. |
| array3,... | Optional. Other arrays to compare with the first array. |
| myfunction | Required. A string that defines a callable comparison function. If the first argument is <, =, > the second argument, the comparison function must return an integer <, =, > 0 accordingly. |
Technical Details
| Return Value: | Returns an intersection array that includes all in the compared array (array1), and also in any other parameter array (array2orarray3etc.) key values. |
|---|---|
| PHP Version: | 5+ |
Complete PHP Array Reference Manual Other Extensions