Reply to Re: Newbie has more is_null woes

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация