Jump to content

Is it possible to add a '1' to a variable and also variable contents?


UG1234

Recommended Posts

 

hi,

 

i would like to add a one to a variable and also the variable contents each time it loops.

 

i need to save the value of a csv file in a variable and there can be many csv files.

 

e.g. My many csv files are name widgets1.csv, widgets2.csv, widgets3.csv etc... i can have upto 50 files.

 

My attempt is below

 

 

 

<?

$t = 1;

while($t < 51; $t++; )

{

$file_to_use$t = "widgets$t.csv";

}

 

thanks for any help in advance

I would recommend you to look into using Arrays. Creating variables such as $var1, $var2, $var3 is not recommended this is what arrays are for.

 

I'd code your loop like so

$files = array();
for($t = 1; $t < 51;  $t++)
{
    $files[] = 'widgets'.$t.'.csv';
}

echo $files[0]; // get the first file, ge widgets1.csv
...
echo $files[6]; // get the fifth file, eg widgets5.csv
//
echo $files[50]; // get the last file, eg widgets51.csv

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.