Search⌘ K
AI Features

Repeating Strings and Characters

Explore how to use Laravel's repeat helper method to repeat strings and characters efficiently. Understand its application through recursive directory listings to format output with indentation, enhancing your string manipulation skills within Laravel.

We'll cover the following...

The repeat helper method

We can use the repeat helper method to repeat an input string a specified number of times.

PHP
<?php
/**
* Versions: Laravel 8, 9
*
* @return string
*/
public static function repeat(
string $string,
int $times
);

As an example, the following code samples would return the value **********:

PHP
<?php
use Illuminate\Support\Str;
Str::repeat('*', 10);
(string) str('*')
->repeat(10);

The following ...