PHP array_intersect_uassoc() Function

Definition

The array_intersect_uassoc() function compares the keys and values of two or more arrays, and returns the matches by using a user-defined key comparison function.

Syntax

PHP array_intersect_uassoc() Function has the following syntax.

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

Parameter

ParameterIs RequiredDescription
array1Required.Array to be compared with
array2Required.Array to be compared with array1
array3,...Optional.Array to be compared with array1
myfunctionRequired.Function used to do the comparison

myfunction defines a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument.

Example

Intersect associate array with user defined function


<?php//  w w w  . j a  v  a  2 s.  c  om
    function myfunction($a,$b){
        if ($a===$b){
          return 0;
        }
        return ($a>$b)?1:-1;
    }
    
    $a1=array("a"=>"A","b"=>"Bed","c"=>"Cat","j"=>"java2s.com");
    $a2=array("d"=>"Dog","b"=>"Bed","p"=>"PHP");
    
    $result=array_intersect_uassoc($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