Definition
The array_udiff() function compares the values of two or more arrays and returns the differences using a user-defined value comparison function.
Syntax
array_udiff(array1, array2, array3, ..., function)
Parameters
Parameter | Description |
---|---|
array1 |
Required. The array to compare from. |
array2 |
Required. An array to compare against. |
array3... |
Optional. More arrays to compare against. |
function |
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 |
Example
<?php
function compare($a, $b){
$a = strtolower($a);
$b = strtolower($b);
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
$array1 = array("apple", "ball", "cat", "dog", "elephant");
$array2 = array("alligator", "DOG", "Elephant", "lion", "Cat");
$result = array_udiff($array1, $array2, "compare");
print_r($result);