Jump to content

Creating Dynamic Variables


meshhat

Recommended Posts

Hello,

 

I'll start by saying I'm a complete newbie to php.  I think what I want to do is fairly simple, though.

 

I'm trying to pass 100 variables (named gain1, gain2...gain100) from a swf to a php file then write these variables to a text file.  Sending the data works fine. 

 

I just need help creating the variables in the php file.  Since all the files have partly the same name, I was hoping to create the variables dynamically.  I was hoping to do something like this:

 

$myFileName = "myfile.txt";
$myFileHandle = fopen($myFileName, 'a') or die("can't open file");

for (i=1; i<100; i++) {
$gaintext + i= $_POST['gaintxt1' + i];
fwrite($myFileHandle, $gain + i);
}

 

However, this isn't working obviously.  Any help?

Link to comment
https://forums.phpfreaks.com/topic/54519-creating-dynamic-variables/
Share on other sites

Thanks for the responses.  Actually no, there are 3 variables being passed.  All the same concept though:

 

gain1, gain2, ...gain100

loss1, loss2, ...loss100

net1, net2, ...net100

 

Yesideez, that didn't seem to work.  I'm passing the variables via a POST. The following variables give me the first respective variable:

$gain = $_POST['gain1'];
$net = $_POST['net1'];
$loss = $_POST['loss1'];

 

I just don't want to do this 100 times for each.  thorpe, I'll try your recommendation.

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.