Re: Generating variable names 'on the fly'

From: Date: Fri, 21 Sep 2001 09:24:31 +0000
Subject: Re: Generating variable names 'on the fly'
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-68121@lists.php.net to get a copy of this message
You can allso do like this: $i = 1; ${"test". $i} = "123"; echo $test1; ___________________________________________ Marcus Rasmussen mail@marcusr.dk On 21-09-01 at 11:21 _lallous wrote: >you can always use eval to create a variable too! > ><? >$i = 1; >eval("\$test$i=123;"); >echo $test1; >?> > >"Neil Freeman" <neil.freeman@asa.co.uk> wrote in message >news:3BAA0EAA.BA5B2DBC@asa.co.uk... >> Hi there, >> >> How do I generate variable names 'on the fly'? I wish to have variable >> names along the lines of $genre_category_1, $genre_category_2, >> $genre_category_3 etc. >> >> Ideally it would be along the lines of this... >> >> ####################### >> $current_field_number = 1; >> $genre_number_fields = 7; >> >> while ($current_field_number < $genre_number_fields) >> { >> //this var will change on every loop >> $genre_desc = $db_movies_genres->Record[$current_field_number]; >> >> //something along the lines of...(you get the idea) >> $str_category = "genre_category_" . $current_field_number; >> $$str_category = $genre_desc; >> >> $current_field_number++; >> } >> ####################### >> >> Any help would be greatly appreciated. >> >> Neil >> -------------------------------- >> Email: neil.freeman@asa.co.uk >> neil_freeman@yahoo.com >> -------------------------------- >> >> > > > >-- >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 (#68121) next »