PHP array_diff_key() ফাংশন

উদাহরণ

দুই এলিমেন্ট সমূহের কী (নাম) তুলনা করে এবং পার্থক্য ফিরিয়ে দেয়:

<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("a"=>"red","c"=>"blue","d"=>"pink");
$result=array_diff_key($a1,$a2);
print_r($result);
?>

Run Instance

সংজ্ঞা ও ব্যবহার

array_diff_key() ফাংশন দুই (বা আরও বেশি) এলিমেন্ট সমূহের কী (নাম) তুলনা করে এবং একটি পার্থক্য ফিরিয়ে দেয়

এই ফাংশন দুই (বা আরও বেশি) এলিমেন্ট সমূহের কী (নাম) তুলনা করে এবং একটি পার্থক্য এলিমেন্ট সমূহ ফিরিয়ে দেয়, যা সমস্ত তুলনা করা এলিমেন্ট সমূহের মধ্যে থাকা না কী (নাম) থাকেarray1)তে থাকে কিন্তু কোনো অন্য প্যারামিটার এলিমেন্ট সমূহের মধ্যে নেই (array2 or array3 etc.) key names.

Description

The array_diff_key() function returns an array that includes all the keys in the compared arrays but not in any other parameter arrays.

Syntax

array_diff_key(array1,array2,array3...);
Parameters Description
array1 Required. The first array to compare with other arrays.
array2 Required. The array to compare with the first array.
array3,... Optional. Other arrays to compare with the first array.

Technical Details

Return Value: Returns an array that contains all the array1 but not in any other parameter array (array2 or array3 etc.) key names.
PHP Version: 5.1+

More Examples

Example 1

Compare the key names of two numeric arrays and return the difference set:

<?php
$a1=array("red","green","blue","yellow");
$a2=array("red","green","blue");
$result=array_diff_key($a1,$a2);
print_r($result);
?>

Run Instance

Example 2

Compare the key names of three arrays and return the difference set:

<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("c"=>"yellow","d"=>"black","e"=>"brown");
$a3=array("f"=>"green","c"=>"purple","g"=>"red");
$result=array_diff_key($a1,$a2,$a3);
print_r($result);
?>

Run Instance