PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




Php Array Function array_diff_ukey()


Tutorials »Php »

Topic

What is array_diff_ukey() Function?



Explanation

The "array_diff_ukey()" function is used to compute the difference of arrays using a callback function based on the keys of the arrays used in comparison.

Syntax:
    array_diff_ukey(array1,array2,array3...,function)

In the above syntax "array1" is the array to be compared with, "array2" is the array to be compared, atleast two arrays should be there, "array 3" is optional. Comparison is done using the "function" specified.

Example
    <?php
    function key_compare_func($key1, $key2)
     {
      if ($key1 == $key2)
      return 0;
      else if ($key1 > $key2)
      return 1;
      else
      return -1;
     }
    $array1 = array('blue'=> 1,'red'=> 2,'green'=> 3,'purple'=> 4);
    $array2 = array('green'=> 5,'blue'=> 6,'yellow'=> 7,'cyan'=> 8);
    var_dump(array_diff_ukey($array1, $array2, 'key_compare_func'));
    ?>
Result:
    array(2) 
     {
      ["red"]=>
      int(2)
      ["purple"]=>
      int(4)
     }

In the above example the "array_diff_ukey" checks for keys in two arrays "array1", "array2" using the function "key_compare_func" based on the keys to display the elements that are not common in both arrays, but present in "array1".





A Note

Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial. Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.

Other Links

web hosting