Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

PHP array_diff_key() Function

by
Category:php
php php array function
PHP array_diff_key() Function

The array_diff_key() function is used to compare the keys from an array against the keys from another array and returns the difference. This function is like array_diff() except the comparison is done on the keys instead of the values.

An array containing all the entries from array1 whose keys are not present in any of the other arrays i.e. array2, array3 etc..

Parameter Description
array1 Required. The array to compare from
array2 Required. An array to compare against
array3,... Optional. More arrays to compare against

Syntax

 array_diff_key(array1,array2,array3...);

Example

$array1=array("a"=>"Prince","b"=>"James","c"=>"Samuel","d"=>"Cooper");
$array2=array("a"=>"Prince","b"=>"James","c"=>"Samuel");
$result=array_diff_key($array1,$array2);
print_r($result);

Output

Array ( [d] => Cooper ) 

 


0 Comments


Html code work in comment box


Related Post