Intersect arrays with additional index check, compares data by a callback function in PHP

Description

The following code shows how to intersect arrays with additional index check, compares data by a callback function.

Example


<?php// w  w  w . j  a  va  2 s.  c o m
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"=>"Blue","c"=>"green");

$result=array_uintersect_assoc($a1,$a2,"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