PHP array_key_exists() Function

PHP array_key_exists() Function is used to check if given key exists in the array. If it returns true, then key exists. If it returns false, then key does not exist. PHP array_keys() function is PHP built-in function.

Syntax :

array_key_exists(string|int $key, array $array);


$key : Required. It is key to be checked in array.

$array : Required. It is input array.

Return : It returns true if the given key or index exists in the array otherwise it returns false.

Let's see below example to understand php array_key_exists() Function in details.

Example :

$array=array("Samsung"=>"M30s","MI"=>"Note 8 pro","iPhone"=>"12 pro","Nokia"=>"X20");
echo "<br>It returns true or false. <br>";

if (array_key_exists("Nokia",$array))
echo "Key exists in array!";
echo "Key does not exist in array!";


Leave a Reply

Your email address will not be published. Required fields are marked *