PHP str repeat

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

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 :

  1. echo str_repeat("-",20);  

  2. echo('
    ');  

  3. echo str_repeat("==",20);  

  4. echo('
    ');  

  5. echo str_repeat("=*=",15);  

  6. ?>   

Output :

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