How to Learn PHP array_diff_uassoc ()
Definition and usage
The array_diff_uassoc () function uses the custom callback function (callback) for index check to calculate the difference set of two or more arrays. Returns an array that contains values in array1 but not in any other parameter array.
Note that, unlike the array_diff () function, the key name must be compared.
The Parameter function is a user-defined function used to compare two arrays. This function must contain two parameters-that is, two key names to be compared. Therefore, the behavior of the array_diff_assoc () function is the opposite. The latter is compared with the internal function.
The key names of the returned array remain unchanged.
Syntax
Array_diff_uassoc (array1, array2, array3., function)
Parameters
Description
Array1 is required. The first array to be compared with other arrays.
Array2 is required. The array to be compared with the first array.
Array3 is optional. The array to be compared with the first array. There can be multiple.
Required. The name of the User-Defined Function.
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:
Array ([0] => Dog [2] => Horse)
Example 2
How to assign multiple arrays to the function:
<? 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"); $ a3 = array (6 => "Bird ", 0 => "Dog", 5 => "Horse"); print_r (array_diff_uassoc ($ a1, $ a2, $ a3, "myfunction");?>
Output:
Array ([2] => Horse)