make string of N characters

◇◆丶佛笑我妖孽 提交于 2019-12-18 05:27:20

问题


Say I have a number=20 and a $value=7.

If I want to make a string of 20 7's using PHP. what's the quickest way to make this?

So output like:

$a='77777777777777777777';

Any functions to make this easier?


回答1:


$a=str_repeat($value,$number);



回答2:


You can use str_repeat(), e.g.

$a=str_repeat('7', 20);



回答3:


Use str_repeat():

$a = str_repeat('7', 20);



回答4:


str_repeat is pretty easy

$a = str_repeat('7', 20);



回答5:


$a = str_repeat('7', 20);

str_repeat()

...or maybe:

$a = str_pad('', 20, '7');

str_pad()



来源:https://stackoverflow.com/questions/9010712/make-string-of-n-characters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!