The str_repeat() function repeats a string a specified number of times.
PHP str_repeat() Function has the following syntax.
str_repeat(string,repeat)
Parameter | Is Required | Description |
---|---|---|
string | Required. | String to repeat |
repeat | Required. | Number of times to repeat. Must be greater or equal to 0 |
PHP str_repeat() function returns the repeated string.
Repeat the string "java2s.com" 3 times:
<?php
echo str_repeat("java2s.com",3);
?>
The code above generates the following result.