How do you validate empty fields in PHP?

1 answer

Answer

1175189

2026-03-22 03:01

+ Follow

PHP provides a function called empty($var), which tests if $var is "empty." Empty has an odd definition, since the function returns true if the variable loosely equates to False. Although a zero-length string would be considered empty, so would the string "0" (among other irrelevant values).

To accept the value "0" from a field, use strlen($var). It tests the length of any variable, after casting it to a string. If this function truly equals integer zero (compared with triple-equals), the variable must be empty.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.