
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
How does the array_diff_key() work in PHP?
It is an inbuilt function that compares the keys of one or more arrays, and returns their difference.
Syntax of the array_diff_key function
array array_diff_key($array1, $array2, ..)
The function can take two or more array names as parameters, and compares the first array with the remaining arrays.
Example
<?php $my_array1 = array("1"=>"Joe", "45"=>"Goldberg", "37"=>"Charolette", "91"=>"Micheal"); $my_array2 = array("1"=>"Joe", "45"=>"Goldberg", "37"=>"Charolette"); $my_array3 = array("1"=>"Joe", "45"=>"Goldberg"); print_r(array_diff_assoc($my_array1, $my_array2, $my_array3)); ?>
Output
Array ( [91] => Micheal )
Inside the <php> tags, three arrays are declared with certain values in them. They are printed by calling the ‘array_diff_assoc’ function by passing all the three arrays to it as parameters. The resultant value is the different between the first array, and second array as well as the difference between the first array and the third array.
- Related Articles
- array_diff_key() function in PHP
- How does the bin2hex() function work in PHP?
- How does the magnets work?
- How does the Microstrip antenna work?
- How does the Selenium WebDriver work?
- How does the discordancy testing work?
- How does the WannaCry malware work?
- How does the Docker network work?
- How does jQuery.scrollTop() work?
- How does jQuery.scrollLeft() work?
- How does classification work?
- How does backpropagation work?
- How does RSA work?
- How does React work?
- How does the “this” keyword work in JavaScript?

Advertisements