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 Link to comment https://forums.phpfreaks.com/topic/134909-solved-how-can-i-repeat-a-string-many-times/ 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++; } Link to comment https://forums.phpfreaks.com/topic/134909-solved-how-can-i-repeat-a-string-many-times/#findComment-702567 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; } Link to comment https://forums.phpfreaks.com/topic/134909-solved-how-can-i-repeat-a-string-many-times/#findComment-702569 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"; } Link to comment https://forums.phpfreaks.com/topic/134909-solved-how-can-i-repeat-a-string-many-times/#findComment-702571 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; } ?> Link to comment https://forums.phpfreaks.com/topic/134909-solved-how-can-i-repeat-a-string-many-times/#findComment-702575 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. Link to comment https://forums.phpfreaks.com/topic/134909-solved-how-can-i-repeat-a-string-many-times/#findComment-702576 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 Link to comment https://forums.phpfreaks.com/topic/134909-solved-how-can-i-repeat-a-string-many-times/#findComment-702577 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; } Link to comment https://forums.phpfreaks.com/topic/134909-solved-how-can-i-repeat-a-string-many-times/#findComment-702581 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.