str_repeat_PHP str_repeat()函数与示例

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值