Name

empty()

Synopsis

    bool empty ( mixed var )

The empty() function returns true if its parameter has a false value. This is not the same as the isset(): if a variable was set and had a false value (such as 0 or an empty string), empty() would return false, and isset() would return true.

    $var1 = "0";
    $var2 = "1";
    $var3 = "";

    if (empty($var1)) print "Var1 empty\n";
    if (empty($var2)) print "Var2 empty\n";
    if (empty($var3)) print "Var3 empty\n";
    if (empty($var4)) print "Var4 empty\n";

That would print "Var1 empty", "Var3 empty", then "Var4 empty".

Get PHP in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.