Home >Backend Development >PHP Tutorial >How to Determine Variable Undefinedness in PHP?
Verifying Variable Undefinedness in PHP
In PHP, the isset() function is commonly used to determine whether a variable is defined. However, it doesn't explicitly check for undefined variables. For that purpose, we can utilize alternative methods:
1. isset($variable)
The isset() function returns true if the variable exists and has a value other than NULL. If the variable is undefined, it returns false.
Example:
<code class="php">$isTouch = isset($variable);</code>
2. empty($variable)
The empty() function returns true if the variable is false, 0, an empty string, NULL, an empty array, or a variable declared without a value. It can be used to check for undefined variables as well.
Example:
<code class="php">$isTouch = empty($variable);</code>
Note:
The above is the detailed content of How to Determine Variable Undefinedness in PHP?. For more information, please follow other related articles on the PHP Chinese website!