PHP array_key_exists() Function
Complete PHP Array Reference Manual
Example
Check whether the key "Volvo" exists in an array:
" XC90 " , " BMW " => " X5 " ) ; if ( array_key_exists ( " Volvo " , $a ) ) { echo " Key exists! " ; } else { echo " Key does not exist! " ; } ?>Run Example »
Definition and Usage
The array_key_exists() function checks whether a specified key exists in an array; it returns true if the key exists and false if it does not.
**Tip:** Remember that if you omit the keys when specifying an array, integer keys starting at 0 and increasing by 1 will be generated. (See Example 2)
Syntax
array_key_exists(
key,array
)
| Parameters | Description |
|---|---|
| key | Required. Specifies the key. |
| array | Required. Specifies the array. |
Technical Details
| Return Value: | Returns TRUE if the key exists, FALSE otherwise. |
|---|---|
| PHP Version: | 4.0.7+ |
More examples
Example 1
Check whether the key "Toyota" exists in an array:
" XC90 " , " BMW " => " X5 " ) ; if ( array_key_exists ( " Toyota " , $a ) ) { echo " Key exists! " ; } else { echo " Key does not exist! " ; } ?>Run Example »
Example 2
Check whether the integer key "0" exists in an array:
Run Example »