Compare keys of three arrays with a user-defined function to compare keys, return matches in PHP

Description

The following code shows how to compare keys of three arrays with a user-defined function to compare keys, return matches.

Example


/*from  www .  j  av a  2  s.c  o  m*/
<?php
function myfunction($a,$b){
   if ($a===$b){
     return 0;
   }
   return ($a>$b)?1:-1;
}

$a1=array("a"=>"red","b"=>"Basic","c"=>"blue");
$a2=array("a"=>"black","b"=>"yellow","d"=>"brown");
$a3=array("e"=>"purple","f"=>"white","a"=>"gold");

$result=array_intersect_ukey($a1,$a2,$a3,"myfunction");
print_r($result);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone