PHP array key exists() - Check if Key Exists in Array
[Pages:3]PHP array_key_exists() ? Check if Key Exists in Array
PHP array_key_exists() Function
The PHP array_key_exists() function checks if a specific key exists in the array. The function returns TRUE if the key is present, else it returns FALSE. array_key_exists() function works for both indexed arrays and associative arrays. For indexed arrays, index is the key.
Syntax ? array_key_exists()
The syntax of array_key_exists() function is array_key_exists( key, array)
where
Parameter Description
key array
[mandatory] The key which we have to search in an array. [mandatory] The array in which we have to search the key.
Function Return Value array_key_exists() returns boolean value TRUE if the key exists and FALSE if the key does not exist.
Example 1: Check an Array for a Specified Key
In this example, we will take an associative array with key-value pairs, and check if specific key "m" is present in the array.
PHP Program
Output
array_key_exists() returns TRUE for the given array and specified key. So, if block is executed.
Example 2: array_key_exists() for Indexed Array
In this example, we will check if a specific index (key) is present in the array. PHP Program
Output The array is also printed to the console to understand the index of items in the array.
Conclusion
In this PHP Tutorial, we learned how to , using PHP Array array_key_exists() function.
PHP Array Functions
PHP array() PHP array_chunk() PHP array_column() PHP array_combine()
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- searching elements in an array linear and binary search
- php create array tutorial kart
- beginner s essential php cheat sheet websitesetup
- php array function pdf ptutorial
- php mock test tutorialspoint
- linear search in an array cornell university
- php array diff key examples
- php form handling atma ram sanatan dharma college
- php array foreach tutorial kart
- sequential search java implementation princeton university
Related searches
- python check if key exists in dictionary
- python check if key exists in map
- check if element is in array javascript
- python check if directory exists and create
- check if class exists javascript
- jquery check if id exists on page
- check if id exists jquery
- check if variable exists javascript
- check if element exists js
- javascript check if element exists in dom
- check if object exists javascript
- powershell check if folder exists and create