'0' as a string with empty() in PHP
You cannot with empty
. From the PHP Manual:
The following things are considered to be empty:
- "" (an empty string)
- 0 (0 as an integer)
- "0" (0 as a string)
- NULL
- FALSE
- array() (an empty array)
- var $var; (a variable declared, but without a value in a class)
You have to add an additional other check.
You can't with only empty(). See the manual. You can do this though:
if ($var !== '0' && empty($var)) { echo "$var is empty and is not string '0'";}
Basically, empty() does the same as:
if (!$var) ...
But it doesn't trigger a PHP notice when the variable is not set.