Re: $VAR = 0 != false

From: Date: Tue, 08 Aug 2000 04:12:38 +0000
Subject: Re: $VAR = 0 != false
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-10584@lists.php.net to get a copy of this message
Heya: "Brian T. Allen" wrote: > > One of the items has an option that is stored in the database as 0 (zero). > > 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 You're right on target with what you're writing, but your not seeing it. The IF statement IS a test. IF statements fail if the test comes out to 0. So, since your variable is 0, the test fails. The statement that you are "testing if the variable is set" is exactly what you're trying to do, so use the isset() function. Enjoy, --Dan -- T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y More than just answers. Solutions. (SM) http://www.analysisandsolutions.com/ 4015 7 Av #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409

« previous php.general (#10584) next »