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
function my_function($a, $b)
{
if ($a === $b) {
return 0;
}
return ($a > $b)? 1:-1;
}
$first=array('One' =>'First','Two'=>'Second','Three'=>'Third','Fourth');
$second=array('One'=> 'First','2nd','Third');
$result=array_udiff($first,$second,"my_function");
while (list ($key, $val) = each ($result)) {
echo "$key -> $val <br>";
}
Output is here.
Two -> Second
0 -> Fourth
Keys of the first index are retained. ( no re-indexing done here) . The element with value Third is not included in output as the value is matching with $second array.
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com