PHP 8.4.24 Released!

Voting

: max(nine, six)?
(Example: nine)

The Note You're Voting On

Alexander Ovsiyenko
8 years ago
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

<< Back to user notes page

To Top