array_diff_ukey(): Difference between two arrays comparing keys through callback function
my_function() : is the callback function to return integer less than , equal to or greater than zero after comparing the keys. Returns all elements of $array1 which are not present in $array2 considering keys. Keys comparison is done through call-back function my_function(). Example with two arrays
Output is here.
Keys of the first index are retained. ( no re-indexing done here) . The element with value Third is included in output as the index or key is not matching with $second array though the value is matching.
Example 2
Output is here
The function my_function() checks the entries and returns 0 if there is a match and returns 1 if no match is found.We are comparing keys only ( not values ) so Third =>33 is matched with Three=>3 so it not appearing in output (as the difference only shown). Similarly FourthH=>4 is not matched with Four=>4 as index or key is compared ( which is not matching ) though the value 4 is matching. Hence it is included in the output. Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
![]() |
|