|
Posted by Rik on 08/04/07 18:00
On Sat, 04 Aug 2007 18:54:27 +0200, Big Moxy <bigmoxy@gmail.com> wrote:
> How does empty() compare to the above? I found this at =
> http://us3.php.net/empty
> -
> <?php
> $var =3D 0;
>
> // Evaluates to true because $var is empty
> if (empty($var)) {
> echo '$var is either 0, empty, or not set at all';
> }
>
> // Evaluates as true because $var is set
> if (isset($var)) {
> echo '$var is set even though it is empty';
> }
Some copy.pasting from the manual for you:
empty() returns true for:
"" (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)
is_null() (hardly used, for good reason) returns true for:
NULL
isset()
Wether or not a variable is set, with one exception: isset() will retur=
n =
FALSE if testing a variable that has been set to NULL. Also note that a =
=
NULL byte ("\0") is not equivalent to the PHP NULL constant.
A variable is considered to be NULL if
- it has been assigned the constant NULL, or
- it has not been set to any value yet, or
- it has been unset (in which case offcourse isset() will also return =
false).
Of all these, a combination of "if(isset($var) && !empty($var)) //some =
code" is the most common.
-- =
Rik Wasmus
[Back to original message]
|