Javatpoint Logo
Javatpoint Logo

PHP array_diff_key() function

This is an inbuilt function of PHP. This function was introduced in PHP 5.1. The array_diff_key() function compares the keys of two or more arrays, and returns entries from array1 that are not present in array2 or array3, etc.

Syntax

Parameter Description Is compulsory
array1 The array to compare from compulsory
array2 An array to compare against compulsory
array3 More arrays to compare against Optional

Return Type

Returns an array containing the entries from array1 that are not present in any of the other arrays.

Example 1

Output:

Array ( [3]=> Boi )

Example 2

Output:

Array(  [20] => Laxman   [30] => Rahul [40] => Ganguly [50] => Yuvi )

Example 3

Output:

Array ( [b] => Bed )

Example 4

Output:

Array ( [a1]=> red  [c3]=> blue  [d4]=> black )



Help Others, Please Share

facebook twitter pinterest