PHP array_udiff_assoc()Functions

PHP Array ReferenceComplete PHP Array Reference Manual

Examples

Compare two arrays'key names and key values(using a built-in function to compare key names, and a user-defined function to compare key values), and returns the difference:

<?php
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_udiff_assoc($a1,$a2,"myfunction");
print_r($result);
?>

Run Example »

Definition and Usage

The array_udiff() function is used to compare two (or more) arrays'key names and key values, and returns the difference.

Note:This function uses a built-in function to compare key names, and uses a user-defined function to compare key values!

This function compares the key names and key values of two (or more) arrays, and returns a difference array that includes all in the compared array (array1) but not in any other parameter array (array2orarray3etc.) of key names and key values.


Syntax

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

Parameters Description
array1 Required. The first array to compare with other arrays.
array2 Required. The array to compare with the first array.
array3,... Optional. Other arrays to compare with the first array.
myfunction Required. A string defining a callable comparison function. If the first argument is <, =, > the second argument, the comparison function must return an integer <, =, > 0 accordingly.

Technical Details

Return value: Returns a difference array that includes all in the compared array (array1) but not in any other parameter array (array2orarray3etc.) of key names and key values.
PHP Version: 5+


PHP Array ReferenceComplete PHP Array Reference Manual Other Extensions