Facebook Page Twitter Page LinkedIn Page
× PHP Tutorial PHP Advanced PHP Resources


The PHP 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.

Syntax

str_repeat(string, repeat)

Parameters

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.

Example:

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

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

  echo $NewString."\n";
?>

The output of the above code will be:

HiHiHiHiHi

❮ PHP String functions