CKTIS / PHP
str_repeat()
Concatenate the input exactly times times.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
str_repeat(string $string, int $times): stringConcatenate the input exactly times times. Zero returns an empty string; a negative count throws ValueError. Byte length grows with the product of input length and count, so account for memory when the count is large.
Signature
str_repeat(string $string, int $times): string
Example output
["ababab",""]
ValueError
Examples
<?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);}
Result
["ababab",""] ValueError