Definitions and usage
The ARRAY_DIFF_UASSOC () function uses a user-defined callback function (callback) to perform an index check to compute the difference set of two or more arrays. Returns an array that includes values that are in array1 but not in any other parameter array.
Note that unlike the Array_diff () function, the key name is also compared.
The parameter function is a user-defined function that compares two arrays, which must have two parameters-that is, two key names to be compared. So the opposite is the behavior of the function Array_diff_assoc (), which is compared with the intrinsic function.
The key name in the returned array remains unchanged.
Grammar
ARRAY_DIFF_UASSOC (array1,array2,array3...,function)
Parameters
Describe
Array1 required. The first array to compare with the other arrays.
Array2 required. The array to compare with the first array.
Array3 Optional. The array to compare with the first array. can have multiple.
function Required. The name of the user-defined function.
Example 1
<?php function MyFunction ($v 1, $v 2) {if ($v 1=== $v 2) {return 0;} if ($v 1> $v 2) {return 1;} else {return-1;}} $ A1=array (0=> "Dog",1=> "Cat",2=> "horse"); $a 2=array (3=> "Dog",1=> "Cat",5=> "horse"); Print_r (ARRAY_DIFF_UASSOC ($a 1, $a 2, "myfunction"));?>
Output:
Array ([0] => Dog [2] => horse)
Example 2
How to assign multiple arrays to this function:
<?php function MyFunction ($v 1, $v 2) {if ($v 1=== $v 2) {return 0;} if ($v 1> $v 2) {return 1;} else {return-1;}} $ A1=array (0=> "Dog",1=> "Cat",2=> "horse"); $a 2=array (3=> "Dog",1=> "Cat",5=> "horse"); $a 3=array (6=> "Bird",0=> "Dog",5=> "horse"); Print_r (ARRAY_DIFF_UASSOC ($a 1, $a 2, $a 3, "myfunction"));?>
Output:
Array ([2] => horse)