PHP str_repeat() Function: Here, we will find out about the str_repeat() Function with Example in PHP.
PHP str_repeat() Function
str_repeat() work is a string capacity in PHP and it is utilized to rehash a given string a given number of times and returns the string.
Syntax:
str_repeat(string, n);
Here,
- the string is the source string to be rehashed.
- n characterizes the quantity of redundancy on the string.
Example:
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
...!...!...!...!...!