PHP str_repeat() Function

PHP str_repeat() function is “used to create a new string by repeating a given string a fixed number of times.”

Syntax

str_repeat(string, repeat)

Parameters

  1. string: It is required and specifies a string to repeat.
  2. repeat: It is a required parameter specifying the number of times the string will be repeated. Must be greater or equal to 0.

Return value

This function returns a new string made up by repeating the given string several times.

Example: How to Use PHP str_repeat() function

<?php

echo str_repeat("Eleven ", 11);

Output

Eleven Eleven Eleven Eleven Eleven Eleven Eleven Eleven Eleven Eleven Eleven

That’s it for this tutorial.

Leave a Comment

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