Fonction str_repeat
La fonction str_repeat répète une chaîne
un nombre de fois spécifié.
Syntaxe
str_repeat(string $string, int $times): string
Exemple
Répétons la chaîne 'x' cinq fois :
<?php
echo str_repeat('x', 5);
?>
Résultat de l'exécution du code :
'xxxxx'
Exemple
Répétons la chaîne '123' trois fois :
<?php
echo str_repeat('123', 3);
?>
Résultat de l'exécution du code :
'123123123'
Voir aussi
-
la fonction
str_pad,
qui complète une chaîne avec une autre chaîne -
la fonction
array_pad,
qui complète un tableau avec des éléments spécifiés -
la fonction
array_fill,
qui remplit un tableau avec une valeur donnée