Re: variable ?

From: Date: Tue, 19 Dec 2000 10:56:06 +0000
Subject: Re: variable ?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-31016@lists.php.net to get a copy of this message
Hi JB! On Mon, 18 Dec 2000, JB wrote: > Well, he wanted to check if a field was set. Using isset($varname) will not > work, because even if a form/field is not filled out, the variable is still > set and passed along, its just set to nothing ( "" ). So do a > if($var!=""){ > print "This Variable Has Been Set!"; > } > else { > print "This Variable Was Not Set!"; > } oh, in this case isset() can be replace w/ !empty(). Empty() is a bit smarter :) cause it looks for two cases: not set, or set but to an empty string/zero value. > > > I have a form that passes 4 of a possible 8 variables to a script.How > can I > > > tell which 4 were passed? > > > Mike P > > > mpeloso@princeton.edu > > here's my favourite: user arrays, namely instead of <input name="var1" > ...> > > use <input name="vars[foo]" ...> so on, then you simply say : > > $stuff = $vars['foo']; > > or the careful programmer with E_ALL and all, would write something along: > > isset($vars['foo']) && ($stuff = $vars['foo']); > > > > cheers, > > -- teodor

« previous php.general (#31016) next »