Does empty() see the value "0" as being empty?

Hi Guys!

I am trying to validate a user form and if they enter “0” does this mean that the empty() function will return true? If so, what can I use instead?

Yes, it does. empty($var) is identical to !$var except it will suppress notice level errors.

It depends, but taking a look at the length of the string using strlen() is usually a decent way to see if you “have something”. You might want to trim() it first because a string comprised of nothing but whitespace may not be desired.

Zaggs, the PHP manual page for empty() lists what is considered as ‘empty’.

You could always check explicitly for ‘empty’ values that you want to allow like empty($var) && $var !== “0”. (: