tags:

views:

78

answers:

6
+2  Q: 

PHP string issue

HI all I have an issue, let say I have $var="z" and how to concatenate the z $i times, for example if $i==5 then $var should be "zzzzz". BTW I would need this in one row.

+5  A: 

You use str_repeat. In your case:

str_repeat($var, $i);
Artefacto
+11  A: 

Use str_repeat:

$repeated = str_repeat($var, $i);

With this $var is repeated $i times.

Gumbo
What’s the reason for the down vote?
Gumbo
i tried to keep a nice votes sequence 6..1 in this thread, but since that didn't work, here's your point back. ;)
stereofrog
+4  A: 
$var = 'z';
$i = 5;
$var = str_repeat($var, $i);
echo $var; // zzzzz
BoltClock
+3  A: 
<?php echo $x = str_repeat("x", 5); // "xxxxx" // Hope it helps, one row ;)
edorian
+2  A: 

Use

str_repeat(String, Multiplier);

EDIT: Wow am I slow ...

Octavian Damiean
+1  A: 

try str_repeat (this should be upvoted once to maintain the sequence)

stereofrog
Here you go :) I've post an answer. Please upvote 6 times :P
codaddict