Definition and usage
The Array_intersect_ukey () function calculates the intersection of an array by comparing the key names with the callback function.
Array_intersect_ukey () returns an array that contains all the values of the key names that appear in the array1 and appear in all other parameter arrays.
This comparison is done through a user-supplied callback function. The function has two parameters, which is two key names to be compared. If the first argument is less than the second argument, the function returns a negative number, or 0 if the two arguments are equal, and returns a positive number if the first argument is greater than the second argument.
Grammar
1 array_intersect_uassoc (array1,array2,array3 ...,function)
| Parameters |
Describe |
| Array1 |
Necessary. The first array to compare with the other array. |
| Array2 |
Necessary. The array to compare with the first array. |
| Array3 |
Optional. The array to compare with the first array. Can have more than one. |
| function |
The name of the user-defined function. |
Example 1
1<?PHP2 functionMyFunction ($v 1, $v 2) {3 if($v 1===$v 2) {4 return0;5 }6 if($v 1>$v 2) {7 return1;8}Else{9 return-1;Ten } One } A$a 1 = Array (0=> "Dog",1=> "Cat",2=> "Horse"); -$a 2 = Array (3=> "Rat",1=> "Bird",5=> "Monkey"); -Print_r (Array_intersect_ukey ($a 1, $a 2, "MyFunction")); the?>
Output:
1 Array ([1] = Cat)
Example 2
How to assign multiple arrays to a function:
1<?PHP2 functionMyFunction ($v 1, $v 2) {3 if($v 1===$v 2) {4 return0;5 }6 if($v 1>$v 2) {7 return1;8}Else{9 return-1;Ten } One } A$a 1 = Array (0=> "Dog",1=> "Cat",2=> "Horse"); -$a 2 = Array (0=> "Rat",1=> "Bird",5=> "Monkey"); -$a 3 = Array (6=> "Dog",7=> "Donkey",0=> "Horse"); thePrint_r (Array_intersect_ukey ($a 1, $a 2, $a 3, "MyFunction")); -?>
Output:
1 Array ([0] = Dog)
PHP Array_intersect_ukey ()