PHP isset() Function
isset()The function is used to detect whether a variable is set and is not NULL.
If a variable has been released using unset(), then checking it with isset() will return FALSE.
If isset() is used to test a variable set to NULL, it will return FALSE.
Also note that the null character ("\0") is not equivalent to PHP's NULL constant.
PHP Version Requirements: PHP 4, PHP 5, PHP 7
Syntax
bool isset ( mixed $var [, mixed $... ] )
Parameter Description:
- $var: The variable to be checked.
If multiple parameters are passed at once, isset() returns TRUE only if all parameters are set. The evaluation proceeds from left to right and stops immediately when it encounters an unset variable.
Return Value
Returns TRUE if the specified variable exists and is not NULL; otherwise, returns FALSE.
Example
Example
The output is:
变量已设置。 bool(true) bool(true) bool(false) bool(false) bool(false)
This also works for elements in an array:
Example
The output is:
bool(true) bool(false) bool(false) bool(true) bool(true) bool(false) bool(false)
Using isset() on String Offsets
PHP 5.4 changed the behavior of isset() when passed string offsets.
Example
The output of the above example in PHP 5.3:
bool(true) bool(true) bool(true) bool(true) bool(true) bool(true)
The output of the above example in PHP 5.4:
bool(false) bool(true) bool(true) bool(true) bool(false) bool(false)Other Extensions
PHP Available Functions