w3resource

PHP: str_repeat() function

Description

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



Inviting useful, relevant, well-written and unique guest posts