您的位置 首页 php

php str_repeat函数怎么用?

php str_repeat()函数用于通过重复给定字符串固定次数来创建新字符串,语法是str_repeat(string,repeat)。它接受一个字符串和一个整数作为参数,并返回一个新字符串,该字符串是通过将作为参数传递的字符串重复由作为该函数的参数传递的整数定义的次数生成的。

php str_repeat函数怎么用?

php str_repeat()函数可以重复使用指定字符串,用于通过重复给定字符串固定次数来创建新字符串,

语法:

str_repeat(string,repeat)

参数:

● string:必须参数,要重复的字符串

● repeat:必须参数,规定字符串重复的次数,必须大于等于0。

返回值:str_repeat返回一个新字符串,该字符串由给定次数重复给定字符串$ string组成。如果传递给函数的参数$ no_of_times等于0,则该函数返回一个空字符串。

示例

<?php$i = "hello world!";$j = str_repeat($i,3);//设置字符串重复的次数为3echo $j;?>

输出:

hello world!hello world!hello world!

以上就是php str_repeat函数怎么用?的详细内容,更多请关注求知技术网其它相关文章!

文章来源:智云一二三科技

文章标题:php str_repeat函数怎么用?

文章地址:https://www.zhihuclub.com/4401.shtml

关于作者: 智云科技

热门文章

网站地图