Home > Article > Backend Development > How to use php str_repeat function?
php The str_repeat() function is used to create a new string by repeating a given string a fixed number of times and return the new string; the syntax is "str_repeat(string,repeat)", and the parameter string specifies to repeat The string parameter repeat specifies the number of times the string is repeated, which must be greater than or equal to 0.
php The str_repeat() function is used to create a new string by repeating a given string a fixed number of times. The syntax is str_repeat(string,repeat). It accepts a string and a
php How to use str_repeat function?
php The str_repeat() function can reuse the specified string. It is used to create a new string by repeating the given string a fixed number of times. The string is repeated by repeating the string passed as a parameter. Generated by the number of times defined by the integer passed as an argument to this function.
Syntax:
str_repeat(string,repeat)
Parameters:
● String: Required parameter, string to be repeated
● repeat: required parameter, specifies the number of times the string is repeated, which must be greater than or equal to 0.
Return value: str_repeat returns a new string consisting of repeating the given string $string a given number of times. If the parameter $no_of_times passed to the function is equal to 0, the function returns an empty string.
Example
<?php $i = "hello world!"; $j = str_repeat($i,3);//设置字符串重复的次数为3 echo $j; ?>
Output:
hello world!hello world!hello world!
The above is the detailed content of How to use php str_repeat function?. For more information, please follow other related articles on the PHP Chinese website!