array_key_exists() function in PHP


The array_key_exists() function checks if the specified key exists in the array. The function returns true if the key exists and false if the key does not exist.

Syntax

array_key_exists(key, arr)

Parameters

  • key − Specify the key to be checked.

  • arr − The array wherein we will find the key.

Return

The array_key_exists() function returns true if the key exists and false if the key does not exist.

Example

 Live Demo

<?php
$arr = array("One"=>"Tennis","Two"=>"Football", "Three"=>"Cricket");
if (array_key_exists("Three",$arr)) {
   echo "Key is in the array!";
} else {
   echo "Key is not in the array!";
}
?>

Output

Key is in the array!

Updated on: 24-Jun-2020

87 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements