How to use array diff ukey in PHP

In this article, I will explain how the array_diff_ukey() function can be used in PHP.
  • 2111

array_diff_ukey() function in PHP

  • The array_diff_ukey() function compares the keys in two or more arrays checking for differences using an additional user function on the keys for comparison.

  • In array_diff_ukey() function, only the keys have to be the same to get a match, both in the automatic comparison and in the user-defined function.

Syntax

array_diff_ukey(array1,array2,array3....,function)

Parameter

  • array1 array1 is required parameter. The first array is the array which will be compared with other arrays.

  • array2 array2 is required parameter. An array to be compared with the first array.

  • array3 array3 is optional parameter. An array to be compared with the first array.

  • function function is required parameter. The function made by user.

Example

The following example show to how the array_diff_ukey() function can be used in PHP.

<h3 style="color: burlywood;">array_diff_ukey() function example in PHP</h3>
<?php
function abc($a1, $a2)
{
if ($a1 == $a2)
return 0;
else if ($a1 > $a2)
return 1;
else
return -1;
}
$array1 = array('Student' => 1, 'Advocate' => 2, 'Engg.' => 3, 'Worker'=> 4);
$array2 = array('Advocate' => 5, 'Engg' => 6, 'Teacher' => 7, 'Co-Worker'=> 8);
var_dump(array_diff_ukey($array1, $array2, 'abc'));
?>

 

Output

diff-ukey.jpg

You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.