|
|
Php Arrays Key Comparison
|
Tutorials » Php »
|
Topic |
What is array_diff_key Function?
|
|
Explanation |
|
The "array_diff_key" function is used to compute the difference of arrays using keys for comparison.
Syntax:
array_diff_key(array1,array2,array3,....)
In the above syntax "array1" is the array to be compared with, "array2" is the array which is to be compared,
atleast two arrays should be there,"array 3" is optional.Comparison is done based on the key.
Example
<?php
$a = array( 'x' => '1','y' => '2','g' => '3');
$b = array( 'x' => '4','y' => '5');
print_r(array_diff_key($a,$b));
?>
Result:
Array
(
[g] => 3
)
In the above example x,y are similar keys, so "g" is displayed.
|
|
A Note |
Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial.
Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.
|
|
|
|