![]() |
VOOZH | about |
The array_key_exists() function in PHP is a built-in function that checks whether a specified key exists in an array. This function is commonly used when working with associative arrays, where keys are explicitly defined, and we need to confirm the presence of a particular key to prevent errors or undesired behaviors when accessing array values.
bool array_key_exists($index, $array)This function accept two paramters that are described below:
Return Value: This function returns a boolean value i.e., TRUE and FALSE depending on whether the key is present in the array or not respectively.
Note: Nested keys will return the FALSE result.
Example 1: This program illustrates the array_key_exists() function to find a key inside an array that holds key_value pair.
Found the Key
If no key_value pair exits, as shown in the below case, then the array takes the default keys i.e. numeric keys starting from zero, into consideration and returns true as far as the $index limit ranges.
Example: This example illustrates the array_key_exists() function in PHP by specifying the particular $index value.
Found the Key
Reference: https://www.php.net/manual/en/function.array-key-exists.php