(PHP 4 >= 4.0.7, PHP 5, PHP 7, PHP 8) Show array_key_exists — Checks if the given key or index exists in the array Descriptionarray_key_exists(string|int Parameterskey Value to check. array An array with keys to check. Return Values Returns
ExamplesExample #1 array_key_exists() example
Example #2 array_key_exists() vs isset() isset() does not return
Notes
See Also
manhon824 at gmail dot com ¶ 11 years ago
❮ PHP Array Reference ExampleCheck if the key "Volvo" exists in an array: <?php Try it Yourself » Definition and UsageThe array_key_exists() function checks an array for a specified key, and returns true if the key exists and false if the key does not exist. Tip: Remember that if you skip the key when you specify an array, an integer key is generated, starting at 0 and increases by 1 for each value. (See example below) Syntaxarray_key_exists(key, array) Parameter Values
Technical Details
More ExamplesExampleCheck if the key "Toyota" exists in an array: <?php Try it Yourself » ExampleCheck if the integer key "0" exists in an array: <?php Try it Yourself » ❮ PHP Array Reference How do you check if a key exists in a PHP array?Answer: Use the PHP array_key_exists() function
You can use the PHP array_key_exists() function to test whether a given key or index exists in an array or not. This function returns TRUE on success or FALSE on failure.
Does key exist in array?Definition and Usage. The array_key_exists() function checks an array for a specified key, and returns true if the key exists and false if the key does not exist.
How do you find the key in an array?You can use array_keys() to get ALL the keys of an array, e.g.
How do you check if an index exists in an array PHP?PHP: Checks if the given key or index exists in an array
The array_key_exists() function is used to check whether a specified key is present in an array or not. The function returns TRUE if the given key is set in the array. The key can be any value possible for an array index.
|