Copyright © tutorialspoint.com

PHP Function array_udiff_uassoc()

previous
Advertisements

Syntax

array_udiff_uassoc ( $array1, $array2 [, $array3 ..., $func1, $func2] );

Definition and Usage

The array_udiff_uassoc() function compares two or more arrays, in two user-made functions, and returns an array containing the elements from the first array, if the user-made functions allow it. The first user-made function compares array keys, and the second compares array values, and both returns a numeric value, a positive number (1) if the returned array should contain this element, and 0, or a negative number (-1), if not.

Paramters

ParameterDescription
array1Required. Specifies an array.
array2Required. Specifies an array to be compared with the first array.
array3Optional. Specifies an array to be compared with the first array.
func1Required. The name of the user-made function that compares the array keys.
func2Required. The name of the user-made function that compares the array values.

Return Values

Returns an array containing all the values from array1 that are not present in any of the other arguments.

Example

Try out following example:

<?php
function func1($v1,$v2) 
{
   if ($v1===$v2)
   {
	   return 0;
   }
   return 1;
}
function func2($v1,$v2)
{
   if ($v1===$v2)
   {
           return 0;
   }
   return 1;
}
$array1 = array("a"=>"orange","b"=>"mango","c"=>"banana");
$array2 = array("a"=>"orange","b"=>"mango","c"=>"apple");
print_r(array_udiff_uassoc($array1,$array2,"func1", "func2"));
?> 

This will produce following result:

Array ( [c]=>banana )
previous

Copyright © tutorialspoint.com