PHP array_uintersect_assoc() Function

Definition

The array_uintersect_assoc() function uses a user function to compare the keys and values of two or more arrays, and returns the matches.

Syntax

PHP array_uintersect_assoc() Function has the following syntax.

array_uintersect_assoc(array1,array2,array3...,myfunction)

Parameter

ParameterIs RequiredDescription
array1Required.The array to compare from
array2Required.An array to compare against
array3,...Optional.More arrays to compare against
myfunctionRequired.Comparison function name.

myfunction must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument.

Example

Uses a user function to compare the keys and values of two or more arrays, and returns the matches


<?php/*from w w w  .j  a  v a  2s  .  co m*/
    function myfunction($a,$b){
       if ($a===$b){
          return 0;
       }
       return ($a>$b)?1:-1;
    }
    
    $a1=array("a"=>"A","b"=>"B","c"=>"C");
    $a2=array("a"=>"A","b"=>"X","c"=>"java2s.com");
    
    $result=array_uintersect_assoc($a1,$a2,"myfunction");
    print_r($result);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions