HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

str_repeat

Description

The str_repeat of String for PHP repeats 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 times · 0

<?

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

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

var_dump($return);
string(0) ""

2 · string times · 1

<?

$string = "Pete and Repeat were in a boat. Pete jumped out. Who was left?\n";
$times = 1;

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

echo $return;
Pete and Repeat were in a boat. Pete jumped out. Who was left?

3 · string times · 10

<?

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

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

echo $return;
Pete and Repeat were in a boat. Pete jumped out. Who was left?
Pete and Repeat were in a boat. Pete jumped out. Who was left?
Pete and Repeat were in a boat. Pete jumped out. Who was left?
Pete and Repeat were in a boat. Pete jumped out. Who was left?
Pete and Repeat were in a boat. Pete jumped out. Who was left?
Pete and Repeat were in a boat. Pete jumped out. Who was left?
Pete and Repeat were in a boat. Pete jumped out. Who was left?
Pete and Repeat were in a boat. Pete jumped out. Who was left?
Pete and Repeat were in a boat. Pete jumped out. Who was left?
Pete and Repeat were in a boat. Pete jumped out. Who was left?