English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP array_udiff_uassoc() Function Usage and Example

PHP Array Function Manual

The array_udiff_uassoc() function is used to calculate the difference set of arrays with index checking, using callback functions to compare data and indices.

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-defined functions and returns an array containing elements from the first array.

Parameter

Serial NumberParameters and Description
1

array1(Required)

It specifies an array.

2

array2(Required)

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

3

array3(Optional)

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

4

func1(Required)

Used to compare array keys, it is the name of the user-defined function.

5

func2(Required)

Used to compare array values, it is the name of the user-defined function.

Return Value

 array_udiff_uassoc() returns an array that includes all the values in the array1 Values that are in the first parameter array but not in any other parameter array.

Online Example

Use a custom function to compare arrays and return an array

<?php
   function func1($v1,$v2) {
      if ($v1 === $v2) {
         return 0;
      }
      return 1;
   }
   
   function func2($v1,$v2) {
      if ($v1 === $v2) {
         return 0;
      }
      return 1;
   }
   $input = array("a"=>"orange","b"=>"mango","c"=>"banana");
   $input1 = array("a"=>"orange","b"=>"mango","c"=>"apple");
   
   print_r(array_udiff_uassoc($input,$input1,"func1", "func2"));
?>
Test and see‹/›

Output Result:

Array ( [c] => banana )

   PHP Array Function Manual