PHP - Function array_diff_ukey()


Advertisements


Syntax

array_diff_ukey ( $array1, $array2 [, $array3...,callback $key_compare_func] );

Definition and Usage

It compares the keys from array1 against the keys from array2 and returns the difference.

Parameters

Sr.No Parameter & Description
1

array1(Required)

The first array is the array that the others will be compared with.

2

array2(Required)

It is an array to be compared with the first array

3

array3(Optional)

It is an array to be compared with the first array

4

key_compare_func(Required)

It is a callback function to use.

Return Values

It returns an array containing all the entries from array1 that are not present in any of the other arrays.

Example

Try out following example −

<?php
   function key_compare_func($v1,$v2) {
      if ($v1 === $v2) {
         return 0;
      }
      
      if ($v1>$v2) {
         return 1;
      }else {
         return -1;
      }
   }
   $input1 = array(0=>"banana", 1=>"orange", 2=>"grapes");
   $input2 = array(3=>"apple",1=>"apricot", 5=>"mango");
   
   print_r(array_diff_ukey($input1,$input2,"key_compare_func"));
?> 

This will produce the following result −

Array ( [0]=>banana [2]=>grapes )

php_function_reference.htm

Advertisements