Definition
The array_uintersect() function compares the values of two or more arrays, and returns the matches.
Syntax
array_uintersect(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($x, $y) {
$x = strtolower($x);
$y = strtolower($y);
if ($x == $y) {
return 0;
}
return ($x < $y) ? -1 : 1;
}
$array1 = array("apple", "ball", "cat", "dog", "elephant");
$array2 = array("alligator", "DOG", "elephant", "lion", "Cat");
$result = array_uintersect($array1, $array2, "compare");
print_r($result);