The best way to check if a variable consists any value or is empty is to use empty function from PHP itself.
1 2 3 4 5 |
$myVar = 0; if (empty($myVar)) { echo '$myVar is either 0, empty, or not set at all'; } |
Though, while coding in PHP it shouldn’t be confused with isset which checks if a variable is set or not set, whether that variable is empty.
1 2 3 4 5 |
$myVar = 0; if (isset($myVar)) { echo '$myVar is set even though it is empty'; } |