PHP array_udiff_assoc() Function
Complete PHP Array Reference Manual
Example
Compare two arrays by theirkeys and values(using a built-in function to compare keys and a user-defined function to compare values), and return the difference:
$b)?1:-1; } $a1=array("a"=>"red","b"=>"green","c"=>"blue"); $a2=array("a"=>"red","b"=>"blue","c"=>"green"); $result=array_udiff_assoc($a1,$a2,"myfunction"); print_r($result); ?>Run Example »
Definition and Usage
The array_udiff() function compares two (or more) arrays by theirkeys and values, and returns the difference.
**Note:** This function uses a built-in function to compare keys and a user-defined function to compare values!
This function compares the keys and values of two (or more) arrays and returns a difference array containing all the keys and values in the compared array (array1) that are not in any of the other argument arrays (array2 or array3 , etc.).
Syntax
array_udiff_assoc(
array1,array2,array3...,myfunction
)
| Parameters | Description |
|---|---|
| array1 | Required. The first array to compare with the other arrays. |
| array2 | Required. An array to compare with the first array. |
| array3,... | Optional. Other arrays to compare with the first array. |
| myfunction | Required. A string defining a callable comparison function. If the first argument is <, =, or > the second argument, the comparison function must return an integer <, =, or > 0 accordingly. |
Technical Details
| Return Value: | Returns a difference array containing all the keys and values in the compared array (array1) that are not in any of the other argument arrays (array2 or array3 , etc.). |
|---|---|
| PHP Version: | 5+ |
Complete PHP Array Reference Manual