str_repeat()
str_repeat() — Repeat a string.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
Signature
str_repeat(string $string, int $times): string
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $string | string | The string to be repeated. |
| $times | int | times has to be greater than or equal to 0. If the times is set to 0, the function will return an empty string. |
Return value
Returns the repeated string.
Example
A runnable snippet:
echo str_repeat("-=", 10);
Output:
-=-=-=-=-=-=-=-=-=-=
Changelog
| Version | Change |
|---|---|
| 8.0.0 | Now throws a ValueError if times is less than 0. Previously, an E_WARNING was raised and null was returned. |
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page str_repeat() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.