The str_repeat Function
The str_repeat
function repeats a string
a specified number of times.
Syntax
str_repeat(string $string, int $times): string
Example
Let's repeat the string 'x'
five times:
<?php
echo str_repeat('x', 5);
?>
Code execution result:
'xxxxx'
Example
Let's repeat the string '123'
three times:
<?php
echo str_repeat('123', 3);
?>
Code execution result:
'123123123'
See Also
-
the
str_pad
function,
which pads a string to a certain length with another string -
the
array_pad
function,
which pads an array to the specified length with a value -
the
array_fill
function,
which fills an array with values