PHP array_key_exists function

Last Updated: February 13, 2022

array_key_exists — You can checks if the given key or index exists in the array

Syntax

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

Supports (PHP 4 >= 4.0.7, PHP 5, PHP 7, PHP 8)

Parameters

key – key to check

array – the array you want to evaluate

Return Value

The return value is a boolean value

Example


<?php
$search_array = array('One' => 1, 'Two' => 4);
if (array_key_exists('One', $search_array)) {
    echo "The 'One' element is in the array";
}
?>

Test