PHP - Function array_diff_key()


Advertisements


Syntax

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

Definition and Usage

Compares array1 against array2 and returns the difference.

Parameters

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
   $a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
   $a2=array("e"=>"red","f"=>"green","g"=>"blue");
   
   $result=array_diff($a1,$a2);
   print_r($result);
?>

This will produce the following result −

Array ( [d] => yellow )

php_function_reference.htm