str_repeat

Repeat a string

Syntax

str_repeat(string $string, int $times): string

Parameters

string

The string to be repeated.

times

The number of times to be repeated.

times has to be greater than or equal to 0. If times is set to 0, the function will return an empty string.

Return

Returns the repeated string.

Examples

1

<?

$string = "Pete and Repeat were in a boat. Pete fell out. Who was left in the boat? ";
$times = 10;

$return = str_repeat($string, $times);

echo $return;

?>
Pete and Repeat were in a boat. Pete fell out. Who was left in the boat? Pete and Repeat were in a boat. Pete fell out. Who was left in the boat? Pete and Repeat were in a boat. Pete fell out. Who was left in the boat? Pete and Repeat were in a boat. Pete fell out. Who was left in the boat? Pete and Repeat were in a boat. Pete fell out. Who was left in the boat? Pete and Repeat were in a boat. Pete fell out. Who was left in the boat? Pete and Repeat were in a boat. Pete fell out. Who was left in the boat? Pete and Repeat were in a boat. Pete fell out. Who was left in the boat? Pete and Repeat were in a boat. Pete fell out. Who was left in the boat? Pete and Repeat were in a boat. Pete fell out. Who was left in the boat? 

2

<?

$string = "Pete and Repeat were in a boat. Pete fell out. Who was left in the boat? ";
$times = 0;

$return = str_repeat($string, $times);

var_dump($return);

?>
string(0) ""

PHP

Home Menu