w3resource

PHP: str_repeat() function

PHP: Repeat a string

The str_repeat() function is used to repeat a string, a specified number of times.

Version:

(PHP 4 and above)

Syntax:

str_repeat(string_name, repeat_no) 

Parameters:

Name Description Required /
Optional
Type
string_name The string to be repeated. Required String
repeat_no Number of times the input string should be repeated. Required Integer

Return value:

The repeated string

Value Type: String

Pictorial Presentation

php-string-str_repeat()

Example:

<?php
echo str_repeat("-",20);
echo('<br>');
echo str_repeat("==",20);
echo('<br>');
echo str_repeat("=*=",15);
?> 

Output :

--------------------
========================================
=*==*==*==*==*==*==*==*==*==*==*==*==*==*==*=

View the example function in the browser

See also

PHP Function Reference

Previous: sscanf
Next: str_shuffle



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/php/function-reference/str_repeat.php