RE: [PHP] if $index=1 how can I create a variable named $column_1

From: Date: Fri, 11 May 2001 18:23:37 +0000
Subject: RE: [PHP] if $index=1 how can I create a variable named $column_1
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-52496@lists.php.net to get a copy of this message
and that's pretty cool ... do you also have a solution to access the name of this "dynamic" variable if I'd like to use it also (e.g. with WDDX functions)? That' would be great! TIA, Arne > -----Original Message----- > From: ..s.c.o.t.t.. [gts] [mailto:scott@graphictype.com] > Sent: Thursday, May 10, 2001 5:07 PM > To: Php-General > Subject: RE: [PHP] if $index=1 how can I create a variable named > $column_1 > > > And even though it's much less elegant than the > solution by Sean below, you could also use 'eval' > > $toast = array("wheat", "rye", "pumpernickel"); > $numbreads = count($toast); > for ($index = 0; $index < $numbreads; $index++) { > eval("\$column$index = '$toast[$index]'; > echo \$column$index . '<BR>';") ; > } > > > -----Original Message----- > > From: Sean R. Bright [mailto:elixer@erols.com] > > To: 'Jay Lepore'; php-general@lists.php.net > > Subject: RE: [PHP] if $index=1 how can I create a variable named > > > > $toast = array("wheat", "rye", "pumpernickel"); > > $numbreads = count($toast); > > for ($index = 0; $index < $numbreads; $index++) { > > ${"column" . $index} = $toasts[$index]; > > } > > > > (A little less code and one less variable required.) > > > > Sean > > > -- > 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 (#52496) next »