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

From: Date: Thu, 10 May 2001 01:51:59 +0000
Subject: RE: [PHP] if $index=1 how can I create a variable named $column_1 by appending $index behind $columnname
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-52215@lists.php.net to get a copy of this message
Woops, you can even do this: $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 > -----Original Message----- > From: Sean R. Bright [mailto:elixer@erols.com] > Sent: Wednesday, May 09, 2001 9:49 PM > To: 'Jay Lepore'; php-general@lists.php.net > Subject: RE: [PHP] if $index=1 how can I create a variable named > $column_1 by appending $index behind $columnname > > > > $toast = array("wheat", "rye", "pumpernickel"); > $numbreads = count($toast); > for ($index = 0; $index < $numbreads; $index++) { > $temp = "column$index"; > $$temp = $toasts[$index] > } > > You will now have variables called column1, column2, and column3. > > Sean > > > -----Original Message----- > > From: Jay Lepore [mailto:jayleporehsd@earthlink.net] > > Sent: Wednesday, May 09, 2001 9:09 PM > > To: php-general@lists.php.net > > Subject: [PHP] if $index=1 how can I create a variable > named $column_1 > > by appending $index behind $columnname > > > > > > I would like to loop through an array and create variable > > names such as > > column1, column2, column3 etc. where the number at the end > > comes from the > > value of index. > > > > For instance: > > > > 1) $toast=array("wheat", "rye", "pumpernickel"); > > 2) $numbreads=count($toast); > > 3) for($index=0;$index<$numbreads;$index++){ > > 4) $column$index=$toasts[$index]; > > 5) } > > > > At the end I would in theory have three fields called > > column1, column2, > > column3. > > > > How can I append $index to another to make a new variable > > name as shown in > > line 4 ? > > > > Thanks in advance > > > > Jay > > > > > > > > -- > > 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 > > > > -- > 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 (#52215) next »