Php

How To Repeat Strings In PHP : str_repeat()

The php str_repeat() function helps to repeat the string the specified number of times.

The str_repeat() function generates a new string by iterating over the given string a predetermined number of times.

PHP str_repeat()

PHP has a built-in function called str_repeat() that repeats a string a specified number of times. The str_repeat() function requires two arguments: a string and an integer. It produces a new string that is created by iterating through a string supplied as an input as many times as the integer passed as an argument to this function allows.

Syntax:

str_repeat(string, repeat)

Whereas:
string : The string parameter is mandatory, and it specifies a repeating string.
repeat : It specifies the number of times the string will be repeated. The value must be greater or equal to 0.

Related Post

If the function’s $repeat parameter is set to 0, the function returns an empty string.

How To Repeat String in PHP

Let’s repeat a string in php.

echo str_repeat("phpflow ", 4);

Output:
phpflow phpflow phpflow phpflow

The function returns a new string created by iterating through the specified string $string.

Recent Posts

Configure and Retrieve S3 Information Using Laravel PHP-AWS-SDK

This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More

4 months ago

What is the Purpose of php_eol in PHP?

in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More

10 months ago

Laravel Table Relationship Methods With Example

This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More

10 months ago

Exploring the Power of Laravel Eloquent Join?

We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More

10 months ago

Quick and Easy Installation of Laravel Valet

in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More

11 months ago

What is Laravel Soft Delete and How Does it Work?

I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More

11 months ago

Categories