Copyright © tutorialspoint.com

PHP Function array_diff_key()

previous
Advertisements

Syntax

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

Definition and Usage

Compares array1 against array2 and returns the difference.

Paramters

ParameterDescription
array1Required. The first array is the array that the others will be compared with.
array2Required. An array to be compared with the first array
array3Optional. 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)
}
previous

Copyright © tutorialspoint.com