Array_diff_assoc () and array_diff_uassoc () function tutorial
Definition and usage
The array_diff_assoc () function compares two or more arrays and returns the entry and value of an array from the first array, only when they do not exist in any other arrays.
Syntax
Array_diff_assoc (array1, array2, array3 ...)
Array1 requirements. The first array, the other will be required with array2. An array is optional relative to the first array array3. An array is relative to the first array. <? Php
$ A1 = array (0 => "Cat", 1 => "Dog";, 2 => "Horse ");
$ A2 = array (0 => "Rat", 1 => "Horse";, 2 => "Dog ");
$ A3 = array (0 => "Horse", 1 => "Dog", 2 => "Cat ");
Print_r (array_diff_assoc ($ a1, $ a2, $ a3 ));
?> Result. array ([0] => Cat [2] => Horse) Now let's take a look at the definition and usage of the array_diff_uassoc () function. The array_diff_uassoc () function compares two or more arrays, check whether there are differences, compare the previous key in a user-defined function, and then return the entry and value of an array from the first array if this function permits it. Array_diff_uassoc (array1, array2, array3., function) parameters describe the requirements of array1. The first array, the other will be required with array2. An array is optional relative to the first array array3. An array is a functional requirement relative to the first array. Note: You can compare the first array with an array, or you like it. Note: The two key values are used for automatic comparison. Then, in the User-Defined Function, only the key is being compared. Example 1 <? Php
Function myfunction ($ v1, $ v2)
{
If ($ v1 ===$ v2)
{
Return 0;
}
If ($ v1> $ v2)
{
Return 1;
}
Else
{
Return-1;
}
}
$ A1 = array (0 => "Dog", 1 => "Cat", 2 => "Horse ");
$ A2 = array (3 => "Dog", 1 => "Cat", 5 => "Horse ");
Print_r (array_diff_uassoc ($ a1, $ a2, "myfunction "));
?> Output is. Array ([0] => Dog [2] => Horse)