PHP Array Function : array_key_exists()

The array_key_exists() function is used to check an array for a specified key, and it returns true if the key exists and false if the key does not exist. The syntax is as follows :
 array_key_exists(key_name, array);
Where key_name is name of the key which you want to check, and array is name of the array.

Example :

  $age = array("John"=> 25, "Sam" => 23, "Marry" => 30, "Luci" => 29);
  if(array_key_exists("Marry", $age)) {
    echo "Key exists!";
  } else {
    echo "Key does not exists!";

Output :

Key exists!

Next Topic :