The array_diff_key() function compares the keys of two (or more) arrays, and returns the differences.
Syntax:array_diff_key(array1,array2,array3...);
In above Syntax,"array1" compare from, "array2" compare against,"array3" compare against to more arrays.
<?php
$array1=array("a"=>"Apple","b"=>"Banana","c"=>"Orange");
$array2=array("a"=>"Apple","c"=>"Orange","d"=>"Mango");
$result=array_diff_key($array1,$array2);
print_r($result);
?>
Output:
Array ( [b] => Banana )
The array_diff_ukey() function compares the keys of two (or more) arrays, and returns the differences.
Syntax:array_diff_uassoc(array1,array2,array3...,myfunction);
In above Syntax,&qu(追記) (追記ここまで)ot;array1" compare from, "array2" compare against,"array3" compare against to more arrays and "myfunction" is a string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument
<?php
function myfunction($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}
$array1=array("a"=>"Apple","b"=>"Banana","c"=>"Orange");
$array2=array("a"=>"Orange","b"=>"Mango","e"=>"Orange");
$result=array_diff_ukey($array1,$array2,"myfunction");
print_r($result);
?>
Output:
Others
Languages
Frameworks
Web / Design
Mobile Technology
Sql & Technology
R4R