str_repeat() Function Use in PHP 8.4 and PHP 8.5

str_repeat() works exactly the same in PHP 8.4 and 8.5 as it did in earlier 8.x versions, but there is one important edge case you must know about.

Usage

The function repeats a string a specified number of times.

Syntax:

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

Example:

<?php
echo str_repeat("-=", 10);
// Output: -=-=-=-=-=-=-=-=-=-=
?>

The $times value must be zero or greater. If it is 0, the function returns an empty string.

3 Views