The array_intersect_ukey() function used for compares the keys of two or more arrays, and returns the common elements.
Note-use a user-defined function to compare the keys
Syntax
array_intersect_ukey(array1,array2,array3...,yourfunction);
Example
function yourfunction($a, $b){
if ($a === $b) {
return 0;
}
return ($a > $b)? 1:-1;
}
$array1 = array("a"=>"red","b"=>"green","c"=>"blue");
$array2 = array("d"=>"red","b"=>"green","e"=>"blue");
print_r(array_intersect_ukey($array1,$array2,"yourfunction"));
Output
Array ( [b] => green )
Copyright ©2022 coderraj.com. All Rights Reserved.