http://php.net/manual/en/function.str-repeat.php#90555
Damien Bezborodov , yeah but execution time of your solution is 3-5 times worse than str_replace.
<?php
function spam($number) {
return str_repeat('test', $number);
}
function spam2($number) {
return implode('', array_fill(0, $number, 'test'));
}
//echo spam(4);
$before = microtime(true);
for ($i = 0; $i < 100000; $i++) {
spam(10);
}
echo microtime(true) - $before , "\n"; // 0.010297
$before = microtime(true);
for ($i = 0; $i < 100000; $i++) {
spam2(10);
}
echo microtime(true) - $before; // 0.032104