PHP str_repeat() Function

PHP str_repeat() function is used to repeat a string a specified number of times.


str_repeat($string, $repeat)


  1. $string(required): It is the string to be repeated.
  2. $repeat(required): It specifies the number of times the string should be repeated. Must be greater or equal to 0. If $repeat is set to 0, the function will return an empty string.

Return value

This function returns a repeated string. 

Visual RepresentationPHP str_repeat() Function

Example: How to Use str_repeat() Function


$str = "Eleven ";

echo str_repeat($str, 5);


Eleven Eleven Eleven Eleven Eleven 

That’s it.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.