PHP array_udiff_uassoc() Function

Definition

The array_udiff_uassoc() function uses two user-defined functions to compare the keys and values of two or more arrays, and returns the differences.

Syntax

PHP array_udiff_uassoc() Function has the following syntax.

array_udiff_uassoc(array1,array2,array3...,myfunction_key,myfunction_value)

Parameter

ParameterIs RequiredDescription
array1Required.Array to compare from
array2Required.Array to compare against
array3,...Optional.More arrays to compare against
myfunction_keyRequired.User-defined function to compare the array keys.
myfunction_valueRequired.User-defined function to compare the array values.

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

Example

Uses two user-defined functions to compare the keys and values of two or more arrays, and returns the differences


<?php/*from   w w w . jav  a 2  s.  c  om*/
function myfunction_key($a,$b){
    if ($a===$b){
      return 0;
    }
    return ($a>$b)?1:-1;
}

function myfunction_value($a,$b){
    if ($a===$b){
      return 0;
    }
    return ($a>$b)?1:-1;
}

$a1=array("a"=>"A","b"=>"HTML","c"=>"java2s.com");
$a2=array("a"=>"Apple","b"=>"CSS","e"=>"PHP");

$result=array_udiff_uassoc($a1,$a2,"myfunction_key","myfunction_value");
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