Home >Backend Development >PHP Problem >PHP check if variable is defined
isset() determines whether the variable has been set
Format: bool isset ( mixed var [, mixed var [, .. .]] )
1. If the variable does not exist, it returns FALSE
2. If the variable exists and its value is NULL, it also returns FALSE
3. If the variable exists and the value is not NULL, TRUE will be returned. When multiple variables are checked at the same time, TRUE will be returned only when each single item meets the previous requirement, otherwise the result will be FALSE.
empty() checks whether the variable is empty
Format: bool empty (mixed var)
1 , If the variable does not exist, it returns TRUE
is_null() to determine whether it is null
Note:
1. Empty and isset will first check whether the variable exists, and then detect the variable value.
is_null just checks the variable value directly to see if it is null, so if the variable is not defined, an error will occur! 2. The empty and isset input parameters must be a variable (php variables start with the $ character), and the is_null input parameter only needs to have a return value. In the PHP manual, their analysis is: empty, isset is a language structure rather than a function, so it cannot be called by variable functions. Recommended tutorial:PHP video tutorial
The above is the detailed content of PHP check if variable is defined. For more information, please follow other related articles on the PHP Chinese website!