Re: testing if var is empty

From: Date: Sat, 21 Jul 2001 11:47:16 +0000
Subject: Re: testing if var is empty
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-59014@lists.php.net to get a copy of this message
Not a solution but some bricks to build it: if (isset ($var)){ ... }else{ ... } isset test if $var is set, but if you once assigned the var even an empty value, this will be true (e.g. after a $var=""; statment, isset will return true). You can unset $var with unset($var); Furthermore if $var contains 0 or "" both will go into the else statement if you write if ($var != ""){ }else{ } thats because for php "" == 0 But you can use === 0 === "" will return false (because 0 is an integer but "" a string) while 0 == "" will return true (because 0 and "" are equal to false) but I think you'll have to combine it because 0 === "somestring" will also return false hope you can use those informations Stefan Rusterholz, scripting@interaktion.ch ---------------------------------- interaktion gmbh Stefan Rusterholz Zürichbergstrasse 17 8032 Zürich ---------------------------------- T. +41 1 253 19 55 F. +41 1 253 19 56 W3 www.interaktion.ch ---------------------------------- ----- Original Message ----- From: "Saquib Farooq" <saquib@isb.sdnpk.org> To: "Dave Freeman" <dfreeman@outbackqld.net.au> Cc: "php" <php-general@lists.php.net> Sent: Saturday, July 21, 2001 11:50 AM Subject: Re: [PHP] testing if var is empty > On Sat, 21 Jul 2001, Dave Freeman wrote: > > > On 21 Jul 01, at 12:07, Justin French wrote: > > > > > I'm a semi-newbie, and if I want to check if a variable is set, or > > > contains something, i've been doing it like this: > > > > > > if($var != "") { ... } > > > > if ($var) > > { > > // $var has been set > > } else { > > // $var has not been set > > } > > > > > > will do what you want. > > > > CYA, Dave > what if the var is set to zero i.e. false. the control will go in > the else part if it is not zero ( not false) it will go in the if control. > > > > > > > > > > > > > ----------------------------------------------------------------------- > > Outback Queensland Internet - Longreach, Outback Queensland - Australia > > http://www.outbackqld.net.au > > mailto:dfreeman@outbackqld.net.au > > ----------------------------------------------------------------------- > > > > > > -- > Saquib Farooq > @ > Systems @ SDNPK > Islamabad > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > >

« previous php.general (#59014) next »