RE: [PHP] Code Advice

From: Date: Wed, 06 Nov 2002 18:50:09 +0000
Subject: RE: [PHP] Code Advice
Groups: php.general 
Request: Send a blank email to php-general+get-123038@lists.php.net to get a copy of this message
> -----Original Message----- > From: Kevin Stone [mailto:kevin@helpelf.com] > Sent: 06 November 2002 18:32 > > The method that you have described below is going to produce > a numerical Key > which is going to result in several errors. Huh? What on earth does this mean? > -Kevin > > ----- Original Message ----- > From: "Jason Young" <jason1@erols.com> > To: <php-general@lists.php.net> > Sent: Wednesday, November 06, 2002 10:52 AM > Subject: [PHP] Code Advice > > > > I (think I) have come up with an interesting little > solution for pages > > that have/can potentially have a lot of get vars, and I > just wanted to > > throw it by everyone to see if I know what I'm talking about... > > > > Instead of having a whole bunch of ... > > "if (isset($_GET['var'])) > > $var = $_GET['var']" > > .. lines on top of each page.. does this code look feasable to you? > > > > ----- > > $get_allow = array('foo', 'bar', 'add', > > 'takeovertheworld'); > > > > while (list($key,$val)=each($get_allow)) > > { > > if (isset($_GET[$key])) > > $$key = $val; > > } Yes, I suppose this is a step up from extract(). Looks fine to me, except that I'd use foreach ($get_allow as $key=>$val) rather than the while() -- comes down to personal preference, I suppose. Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#123038) next »