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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.