Re: Accessing variables, with a for-loop

From: Date: Tue, 20 Jun 2000 13:44:34 +0000
Subject: Re: Accessing variables, with a for-loop
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-2298@lists.php.net to get a copy of this message
Try: <html><body> <?php $var1 = "one"; $var2 = "two"; $var3 = "three"; $varheader = "var"; for ($i=1;$i<4;$i++) { $contents = ${"$varheader"."$i"}; echo "$i) $contents <BR>"; } ?> </body></html> David. ----- Original Message ----- From: Erlend Strømsvik <stromsvi@tapir.no> To: <php-general@lists.php.net> Sent: Monday, June 19, 2000 1:30 PM Subject: [PHP-GENERAL] Accessing variables, with a for-loop > I have gotten some old code for which I have to make some changes to. And in > the code you have places where the person haven't used arrays but have code > like this : > $variable1 = > $variable2 = > $variable3 = > $variable4 = > $variable5 = > > Now I wonder if it could be possible to access these variables this way (or > in some other easy way?) > > for ($i = 0; i < max; i++) { > $variable$i // -Hmmmm Can I do this in some way? :) > } > > Had it been an array I could just have written $variable[i]; but since the > codes have several places with the kind of "stupid" code I mentioned > earlier, it would make things much more easy for me if I could access them > in a for or while loop. > > I haven't used php much, but I'm trying to learn it now.... :) > > > Erlend Stromsvik > > > -- > 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 (#2298) next »