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