str_repeat
PHP str_repeat()函数 (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.
str_repeat()函数是PHP中的字符串函数,用于将给定的字符串重复给定的次数并返回该字符串。
Syntax:
句法:
str_repeat(string, n);
Here,
这里,
string is the source string to be repeated.
string是要重复的源字符串。
n defines the number of repetition on the string.
n定义字符串上的重复次数。
Examples:
例子:
Input:
str = "Hello"
n = 3
Output:
"HelloHelloHello"
Input:
str = "Okay "
n = 4
Output:
"Okay Okay Okay Okay"
PHP code:
PHP代码:
<?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
...!...!...!...!...!
翻译自: https://www.includehelp.com/php/str_repeat-function-with-example.aspx
str_repeat