str_repeat

(PHP 4, PHP 5, PHP 7, PHP 8)

str_repeat重復(fù)一個(gè)字符串

說(shuō)明

str_repeat(string $input, int $multiplier): string

返回 input 重復(fù) multiplier 次后的結(jié)果。

參數(shù)

input

待操作的字符串。

multiplier

input 被重復(fù)的次數(shù)。

multiplier 必須大于等于 0。如果 multiplier 被設(shè)置為 0,函數(shù)返回空字符串。

返回值

返回重復(fù)后的字符串。

范例

示例 #1 str_repeat() 范例

<?php
echo str_repeat("-="10);
?>

以上例程會(huì)輸出:

-=-=-=-=-=-=-=-=-=-=

參見

  • for
  • str_pad() - 使用另一個(gè)字符串填充字符串為指定長(zhǎng)度
  • substr_count() - 計(jì)算字串出現(xiàn)的次數(shù)