'0' as a string with empty() in PHP
You cannot make empty() take it. That is how it was designed. Instead you can write an and
statement to test:
if (empty($var) && $var !== '0') {
echo $var . ' is empty';
}
You could use isset
, unless of course, you want it to turn away the other empties that empty
checks for.
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.