PHP Tutorial PHP Advanced PHP Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

PHP - String str_repeat() Function

The PHP String str_repeat() function is used to repeat the given string by specified number of times. The function has an required argument which is used to specify the number of repetition.


str_repeat(string, repeat)


string Required. Specify the string to repeat
repeat Required. Specify the number of times the string will be repeated. It must be greater than 0.

Return Value

Returns the repeated version of the specified string.


In the example below, str_repeat() function is used to repeat the string MyString by five times.

$MyString = "Hi";
$NewString = str_repeat($MyString, 5);

echo $NewString."\n";

The output of the above code will be:


❮ PHP String functions