PunjabHaker Posted February 5, 2007 Share Posted February 5, 2007 if the string value is "2" i want to write 2 strings like "string1, string2" if the string value is "3" i want to write 3 strings like "string1, string2, string3" how can i do this ? please help urgently thanks Link to comment https://forums.phpfreaks.com/topic/37178-please-help-with-a-string/ Share on other sites More sharing options...
ted_chou12 Posted February 5, 2007 Share Posted February 5, 2007 $generate = 1; while ($generate <= $number) {echo "string$generate";$generate++;} try this; Ted Link to comment https://forums.phpfreaks.com/topic/37178-please-help-with-a-string/#findComment-177588 Share on other sites More sharing options...
craygo Posted February 5, 2007 Share Posted February 5, 2007 Ted's is sweet and to the point. Here is one pretty much the same but stores the loop in a variable. <?php $generate = 6; $line = ''; for($i=1; $i<=$generate; $i++){ $line .= "String$i, "; // add each loop into one variable } echo substr($line, 0, -2); // echo the string and get rid on the last comma and space ?> Ray Link to comment https://forums.phpfreaks.com/topic/37178-please-help-with-a-string/#findComment-177644 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.