Definition and usage
Array_diff_ukey () returns an array that contains all the values that appear in the array1 but do not appear in any of the other parameter array's key names. Note that the association relationship remains unchanged. Unlike Array_diff (), comparisons are made by key names rather than values.
This comparison is done through a user-supplied callback function. If you think that the first parameter is less than, equal to, or greater than the second argument, you must return an integer less than 0, equal to zero, or greater than 0, respectively.
Grammar
Array_diff_ukey (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 |
Necessary. The name of the user-defined function. |
Example 1
<?phpfunction MyFunction ($v 1, $v 2) { if ($v 1=== $v 2) { return 0; } if ($v 1> $v 2) { return 1; } else{ return-1; }} $a 1 = Array (0=> "Dog",1=> "Cat",2=> "Horse"), $a 2 = Array (3=> "Rat",1=> "Bird",5=> "Monkey");p Rint_r ( Array_diff_ukey ($a 1, $a 2, "myfunction"));? >
Output:
Array ([0] = Dog [2] = Horse)
Example 2
How to assign multiple arrays to the function:
<?phpfunction MyFunction ($v 1, $v 2) { if ($v 1=== $v 2) { return 0; } if ($v 1> $v 2) { return 1; } else{ return-1; }} $a 1 = Array (0=> "Dog",1=> "Cat",2=> "Horse"), $a 2 = Array (3=> "Rat",1=> "Bird",5=> "Monkey"), $a 3 = array ( 6=> "Dog",7=> "Donkey",0=> "Horse");p Rint_r (Array_diff_ukey ($a 1, $a 2, $a 3, "myfunction")); >
Output:
Array ([2] = Horse)
PHP Array_diff_ukey ()