How to Learn PHP array_diff_ukey ()
Definition and usage
Array_diff_ukey () returns an array containing all the key names that appear in the array of array1 but are not displayed in any other parameter. Note that the link remains unchanged. Unlike array_diff (), the comparison is based on the key name rather than the value.
This comparison is performed through the callback function provided by the user. If the first parameter is considered to be less than, equal to, or greater than the second parameter, an integer less than zero, equal to zero, or greater than zero must be returned.
Syntax
Array_diff_ukey (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 => "Rat", 1 => "Bird", 5 => "Monkey"); print_r (array_diff_ukey ($ 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 => "Rat", 1 => "Bird", 5 => "Monkey"); $ a3 = array (6 => "Dog ", 7 => "Donkey", 0 => "Horse"); print_r (array_diff_ukey ($ a1, $ a2, $ a3, "myfunction");?>
Output:
Array ([2] => Horse)