The array_udiff()
function compares the values of two or more arrays and returns the differences using a user-defined value comparison function.
This is unlike array_diff()
which uses an internal function for comparing the values.
This function compares the values of two (or more) arrays, and return an array that contains the entries from array1 that are not present in array2 or array3, etc.
array_udiff(array1, array2, array3, ..., myfunction)
Parameter | Description |
---|---|
array1 | Required. The array to compare from |
array2 | Required. An array to compare against |
array3,... | Optional. More arrays to compare against |
myfunction | 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 |
Example1 : As we can see followinng example compare two arrays (user define function to compare the values) and return the diffierences.
.
Output :
Array
(
[a] => Web
[b] => Designing
)
Example 2 : The following example shows how to compare the values of three arrays and get the differences using the PHP's built-in strcasecmp()
function as value comparison function.
Output :
Array
(
[1] => bat
[3] => dog
)