UG1234 Posted February 12, 2010 Share Posted February 12, 2010 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 Link to comment https://forums.phpfreaks.com/topic/191894-is-it-possible-to-add-a-1-to-a-variable-and-also-variable-contents/ Share on other sites More sharing options...
wildteen88 Posted February 12, 2010 Share Posted February 12, 2010 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 Link to comment https://forums.phpfreaks.com/topic/191894-is-it-possible-to-add-a-1-to-a-variable-and-also-variable-contents/#findComment-1011451 Share on other sites More sharing options...
roopurt18 Posted February 12, 2010 Share Posted February 12, 2010 You might also take a look at the glob() function. Link to comment https://forums.phpfreaks.com/topic/191894-is-it-possible-to-add-a-1-to-a-variable-and-also-variable-contents/#findComment-1011454 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.