Home » PHP

PHP str_repeat() Function with Example

PHP str_repeat() Function: Here, we are going to learn about the str_repeat() Function with Example in PHP.
Submitted by IncludeHelp, on February 05, 2019

PHP str_repeat() Function

str_repeat() function is a string function in PHP and it is used to repeat a given string a given number of times and returns the string.

Syntax:

    str_repeat(string, n);

Here,

  • string is the source string to be repeated.
  • n defines the number of repetition on the string.

Examples:

    Input:
    str = "Hello"
    n = 3
    Output:
    "HelloHelloHello"

    Input:
    str = "Okay "
    n = 4
    Output:
    "Okay Okay Okay Okay"

PHP code:

<?php
    $str = "Hello";
    $output = str_repeat($str,3);
    echo ($output."\n");

    $str = "Okay ";
    $output = str_repeat($str,4);
    echo ($output."\n");    

    $str = "...!";
    $output = str_repeat($str,5);
    echo ($output."\n");    
?>

Output

HelloHelloHello
Okay Okay Okay Okay 
...!...!...!...!...!





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.