gibigbig Posted January 30, 2011 Share Posted January 30, 2011 I have a string, and I have a variable $var = 5; $str = '<img src="img.jpg" />'; i want to display a $str (the image) $var amount of times (5). how can I do this? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 30, 2011 Share Posted January 30, 2011 str_repeat Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted January 30, 2011 Share Posted January 30, 2011 Or you could do it the convoluted way: <?php $str = '<img src="img.jpg" />'; for ($x=1; $x <= 6; $x++) { echo $str; } ?> That is what I would have done. However, I did not know about the str_repeat() function until he posted it. Wish I had of known about that in the past. So this post helped me out as well. Simplifies things. Quote Link to comment Share on other sites More sharing options...
gibigbig Posted January 30, 2011 Author Share Posted January 30, 2011 thank you both of you for your input, this helped my project greatly 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.