How to use array diff key in PHP

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

array_diff_key() function in PHP

  • The array_diff_key() function compares two or more arrays, and returns the difference.

  • In array_diff_key() function, only the key is used in the comparison.

Syntax

array_diff_key(array1,array2,array3....)

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.

Example

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

<h3 style="color: darkgreen;">array_diff_key() function example in PHP</h3>
<?php
$i1=array(0=>"Nitin",1=>"Manish",2=>"Aman");
$i2=array(2=>"Rajesh",3=>"Saurabh",4=>"Ravi");
$i3=array(5=>"Arvind",6=>"Sunny",7=>"Neeraj");
print_r(array_diff_key($i1,$i2,$i3));
?>

 

Output

diff- key.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

© 2020 DotNetHeaven. All rights reserved.