How to use str repeat in PHP

In this article I will explain how the str_repeat() function can be used in PHP.
  • 1894

str_repeat() function in PHP

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

Syntax

str_repeat(string,repeat)

Parameter

  • string string is required parameter. it is specify for repeat to string.
  • repeat length is required parameter. it is specify for the number of times the string will be repeated. it must be greater or equal to 0.
Example

The following example show to how the str_repeat() function can be used in PHP.

<html>

<body>

<h3 style="color: violet;">str_repeat() function example in PHP</h3>

    <?php

    echo str_repeat("*",20);

    echo('<br>');

    echo str_repeat("*=",20);

    echo('<br>');

    echo str_repeat("/=*=/",10);

    echo('<br>');

    echo str_repeat("<>",15);

    echo('<br>');

    echo str_repeat("?",25);

    echo('<br>');

    echo str_repeat("{}",15);

    echo('<br>');

    echo str_repeat(":-",15);

    ?>

</body>

</html>

 

Output

str-repeat-php.gif
You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.