[thelist] building a dynamic variable in php

Tom Dell'Aringa pixelmech at yahoo.com
Mon Jan 13 12:15:01 CST 2003


--- Carl J Meyer <cjmeyer at npcc.net> wrote:
> Tom,
>
> On Mon, 2003-01-13 at 09:58, Tom Dell'Aringa wrote:
> > Would an array be better? How would I do it with an array?
>
> Hard to say much more without knowing the details of your task and
> the
> rest of the script.  DavidU gave simple code for transferring the
> values
> from $_POST to a $mail array and made some good suggestions (i.e.
> using
> list() to put the values in variables that more accurately reflect
> their
> contents, whatever those might be).
>
> Really depends on what you're doing with the data...

Right, my bad guys. I have a send to friend list where they can send
a link to 10 friends. Psuedocode:

get 10 post variables as i
if i is set
   send a mail to i
end

So I want the mail() code within the loop so I don't have to repeat
the code, and just use variables for the data. The body and all that
info is all the same except the receipient of course.

Does an array make sense in this context? Here is my current code:
-------------------------------------------------
for($i = 1; $i<=10; $i++)
{
	$var = "mail" . $i;
	${$var} = $_POST[$i];

	$body = "body of email";

	mail(${$var}, "From $personA/$personB", $body, "From:
$email\r\nReply-To: $email\r\n");
}
--------------------------------------------------
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



More information about the thelist mailing list