Displaying multiple values depending on arrays

This is tough to word, but I’m trying to get an image to pop up for every 1 value in an array.

Say; $totalrep = 5

Now, I want this image to be displayed 5 times. If $totalrep = 4, I want the image to be displayed 4 times.

$repimg = "<img src=\\"imgurl here\\">";
$repstars = "{$totalrep} * {$repimg}";
echo $repstars;

^^ That is currently what I’m trying, but you can’t multiply a value and a script. I think I need to find another way to do this.

Any ideas?

for($i = 0; $i < $totalrep; $i++)
  echo '<img src="url">';

And that’s that. =p

Thank you.

I was unaware about the for statement. I was trying to find a way to use foreach, but am not sure how that works either.

I looked into it on php.net/for and sounds like you made it work. Thanks a ton!

This is how you could have done it with foreach().

// given
$totalRep = 5;

// range returns an array
$r = range(1, $totalRep);

// so now you can iterate through it
foreach( $r as $img){
echo $img;