• PHP Video Tutorials

PHP - Function array_udiff_assoc()



Syntax

array_udiff_assoc ( $array1, $array2 [, $array3 ..., $data_compare_func] );

Definition and Usage

It computes the difference of arrays with additional index check, compares data by a callback function and returns an array containing all the values from array1 that are not present in any of the other arguments.

Parameters

Sr.No Parameter & Description
1

array1(Required)

It specifies an array.

2

array2(Required)

It specifies an array to be compared with the first array.

3

array3(Optional)

It specifies an array to be compared with the first array.

4

data_compare_func*(Required)

The name of the user-made function.

Return Values

It 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 call_back_function($v1,$v2) {
      if ($v1 === $v2) {
         return 0;
      }
      return 1;
   }
   $input = array("a"=>"orange","b"=>"orange","c"=>"mango");
   $input1 = array("a"=>"orange","b"=>"mango","c"=>"orange");
   
   print_r(array_udiff_assoc($input,$input1,"call_back_function"));
?> 

This will produce the following result −

Array ( [b] => orange [c] => mango )
php_function_reference.htm
Advertisements