Home >Backend Development >PHP Tutorial >How to Check for Undefined Values in PHP
Determining Undefined Values in PHP
In PHP, unlike JavaScript, the isset() function is not solely used to check if a variable is undefined. It verifies whether a variable is declared and not explicitly set to NULL. To address the question of checking for undefined values, consider the following solutions:
isset() Function:
<code class="php">$isTouch = isset($variable);</code>
This will return true if the variable is defined, and false if it's undefined or set to NULL.
Empty() Function:
<code class="php">$isTouch = empty($variable);</code>
empty() further verifies that a variable is undefined or contains false, 0, 0.0, "0", NULL, an empty array, or a declared variable without a value.
Note:
empty() works for the following values:
The above is the detailed content of How to Check for Undefined Values in PHP. For more information, please follow other related articles on the PHP Chinese website!