[thelist] building a dynamic variable in php

Carl J Meyer cjmeyer at npcc.net
Mon Jan 13 11:55:01 CST 2003


Hi Tom,  here's the code you need,

-------------
for($i = 1; $i < 10; $i++) {
  $var = 'mail' . $i;
  ${$var} = $_POST[$i];
}
-------------

This will set the variables $mail1 through $mail10.  'Course I rarely
see any reason to do this sort of thing when you could just use an array
( $mail[1] through $mail[10] )...

Carl


On Mon, 2003-01-13 at 09:46, Tom Dell'Aringa wrote:
> Hello,
>
> I'm building a 'mail to friend' list where I have 10 form fields
> labeled 1 through 10. In my php that processes the page, I thought
> instead of doing:
>
> $mail1 = $_POST["1"];
>
> I would instead run through a loop to do it:
>
> for($i = 1; $i <= 10; $i++) {
>
> then I would dynamically set each variable. This was what I tried:
>
> $mail . i = $_POST[i];
>
> but this of course did not work. There must be a good way to do this
> I would think...
>
> Tom
>
> =====
> var me = tom.pixelmech.webDeveloper();
>
> http://www.pixelmech.com/
> http://www.maccaws.com/
> [Making A Commercial Case for Adopting Web Standards]
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
> --
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !





More information about the thelist mailing list