Compare keys and values of three arrays with user-defined function to compare keys, return differences in PHP

Description

The following code shows how to compare keys and values of three arrays with user-defined function to compare keys, return differences.

Example


/* w w  w.  j ava2 s .  co m*/
<?php
   function myfunction($a,$b){
      if ($a===$b){
         return 0;
      }
      return ($a>$b)?1:-1;
   }

   $a1=array("a"=>"red","b"=>"green","c"=>"blue");
   $a2=array("a"=>"red","b"=>"Basic","d"=>"Dart");
   $a3=array("e"=>"yellow","a"=>"red","d"=>"blue");

   $result=array_diff_uassoc($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