Compare values of three arrays with user function to compare values, return differences in PHP

Description

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

Example


// ww w .  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"=>"green","c"=>"blue","yellow");
$a2=array("A"=>"red","b"=>"GREEN","yellow","black");
$a3=array("a"=>"green","b"=>"red","Yellow","black");

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