CKTIS / PHP
str_repeat()
Concatena il numero esatto di copie indicato.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
str_repeat(string $string, int $times): stringConcatena il numero esatto di copie indicato. Zero dà la stringa vuota e un conteggio negativo genera ValueError. La lunghezza in byte cresce con il prodotto della lunghezza iniziale per le copie e grandi ripetizioni richiedono memoria.
Firma
str_repeat(string $string, int $times): string
Output dell’esempio
["ababab",""]
ValueError
Esempi
<?php
echo json_encode([str_repeat("ab",3),str_repeat("ab",0)]),PHP_EOL;
try{str_repeat("x",-1);}catch(ValueError $e){echo get_class($e);}
Risultato
["ababab",""] ValueError