npsari Posted November 30, 2008 Share Posted November 30, 2008 Hello there, I want to repeat this string 100 times $string = "Hello there"; The way i do it now is like that... print"$string"; print"<br>"; print"$string"; print"<br>"; print"$string"; print"<br>"; print"$string"; print"<br>"; print"$string"; 100 times... :-\ Do you know of any easier way please Quote Link to comment Share on other sites More sharing options...
josephman1988 Posted November 30, 2008 Share Posted November 30, 2008 $limit = 0; if ($limit <= 100; ) { print $string; $limit++; } Quote Link to comment Share on other sites More sharing options...
gevans Posted November 30, 2008 Share Posted November 30, 2008 not if statement, for statement $count = 100; for($i=0;$i<$count;$i++){ echo $string; } Quote Link to comment Share on other sites More sharing options...
trq Posted November 30, 2008 Share Posted November 30, 2008 $limit = 0; if ($limit <= 100; ) { print $string; $limit++; } That won't do anything. You need a loop. for ($i = 1;$i == 100; $i++) { $string = "Hello there"; } Quote Link to comment Share on other sites More sharing options...
josephman1988 Posted November 30, 2008 Share Posted November 30, 2008 My bad, my mistake: <?php $string = "1<br />"; for ($limit = 0; $limit <= 100; $limit++ ) { print $string; } ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 30, 2008 Share Posted November 30, 2008 Or, shock horror, you could use the string repeat function. Sometimes i wonder why google bother making a search engine. Quote Link to comment Share on other sites More sharing options...
npsari Posted November 30, 2008 Author Share Posted November 30, 2008 not if statement, for statement $count = 100; for($i=0;$i<$count;$i++){ echo $string; } Thank you, this one worked Guys, the other ones did not work Thank you much for the support Quote Link to comment Share on other sites More sharing options...
npsari Posted November 30, 2008 Author Share Posted November 30, 2008 Ohh, ok, Just to sum up The two ones that worked are... $string = "1<br />"; for ($limit = 0; $limit <= 100; $limit++ ) { print $string; } $count = 100; for($i=0;$i<$count;$i++){ echo $string; } 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.