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

ParameterTypeWhat it takes
$stringstringThe string to be repeated.
$timesinttimes 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

VersionChange
8.0.0Now throws a ValueError if times is less than 0. Previously, an E_WARNING was raised and null was returned.

See also

str_pad(), substr_count()

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.