Web | This Site

Learning PHP
Advanced PHP
PHP Function Reference
PHP Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM

| Home |  | References |  | Discussion Forums |  | About TP

# PHP Function array_diff_key()

## Syntax

array array_diff_key ( array $array1, array $array2 [, array $...] );

## Definition and Usage

Compares array1 against array2 and returns the difference.

## Paramters

Parameter | Description
--- | ---
array1 | Required. The first array is the array that the others will be compared with.
array2 | Required. An array to be compared with the first array
array3 | Optional. An array to be compared with the first array

## Return Values

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
    $array1 = array('blue'  => 1, 'red'  => 2, 'purple' => 3);

    $array2 = array('blue' => 4, 'yellow' => 5, 'cyan'  => 6);

    var_dump(array_diff($input_array1, $input_array2));
    ?>

This will produce following result:

    array(2) {
      ["red"]=>
      int(2)
      ["purple"]=>
      int(3)
    }

Advertisement

Online Image Processing

Indian Baby Names