Re: [PHP] $VAR = 0 != false From: Andre Fadel (fadel <email protected>)
Date: 08/07/00

Description

int empty(mixed var);

Returns false if var is set and has a non-empty or non-zero value; true
otherwise.

That means that if it's zero i will return true. You're using not (!) so
it returns false.
Stick with isset(), which is suitable for what you need.

--
André Fadel
fadel <email protected>
Hoje E Sempre GUARANI!

On Mon, 7 Aug 2000, Brian T. Allen wrote:

> Hi *, > > I have an ecommerce site where the shopping cart supports options for items. > > One of the items has an option that is stored in the database as 0 (zero). It doesn't mean false, it means that an option was selected, and the option was 0. > > If I echo out the variable, you get "0" echoed out. > > $VAR = "0"; > echo $VAR; > > You get what you would expect. > > But, if you verify the variable exists first: > > if($VAR){ > echo $VAR; > } > > You get nothing, even though the variable is set. It is set to zero, granted, but it is set! > > I can understand that in some types of tests you want 0 to be synonimous with false, but here I am only testing if the variable is set to a value, be it false, 0, or something else. > > I just tested, and isset() works like I think it should (I am NOT the source of all truth and knowledge, just trying to make this make sense), but !empty() does not: > > if(!empty($VAR)){ > echo $VAR; > } > > even though $VAR isn't empty. > > Thoughts, comments, flames? > > Thanks, > Brian > >

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>