The array_key_exists Function

The array_key_exists function checks for the presence of a specified key in an array.

Syntax

phparray_key_exists(string|int $key, array $array): bool

Example

Let's check for the presence of the key 'a' in the array $arr:

php<?php
  $arr = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5];
  
  $res = array_key_exists('a', $arr);
  var_dump($res);
?>

Code execution result:

phptrue

See Also

  • the in_array function,
    which checks for the presence of a value in an array
  • the array_keys function,
    which returns array keys