Repeat a line several times

You can repeat a string several times using the str_repeat() function.

str_repeat('PHP ', 3); // PHP PHP PHP

If you specify "0" as the value, the str_repeat() function will return an empty string.

If you enter a negative value, PHP will return an error ”Fatal error: Uncaught ValueError: str_repeat(): Argument #2 ($times) must be greater than or equal to 0“).

str_repeat('PHP ', -1); // Error: Value must be zero or greater than zero

The function was introduced in PHP 4.