PHP - Function array_diff_key()


Advertisements


Syntax

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

Definition and Usage

It compares array1 against array2 and returns the difference.

Parameters

Sr.No Parameter & Description
1

array1(Required)

This first array 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

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
   $input1 = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow", "f"=>"yellow");
   $input2 = array("a"=>"red","b"=>"green","c"=>"blue");

   $result = array_diff_key($input1,$input2);
   print_r($result);
?>

This will produce the following result −

Array ( [d] => yellow )

php_function_reference.htm

Advertisements