Fonction str_repeat

La fonction str_repeat répète une chaîne un nombre de fois spécifié.

Syntaxe

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

Exemple

Répétons la chaîne 'x' cinq fois :

php<?php
  echo str_repeat('x', 5);
?>

Résultat de l'exécution du code :

php'xxxxx'

Exemple

Répétons la chaîne '123' trois fois :

php<?php
  echo str_repeat('123', 3);
?>

Résultat de l'exécution du code :

php'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