gpt4 book ai didi

PHP - 列出带有网址的号码

转载 作者:可可西里 更新时间:2023-11-01 01:02:32 26 4
gpt4 key购买 nike

像这样的 php 示例:

  for ($i=1; $i<=20; $i++){
$url = "http://example.org/12".$i."<br />";
echo $url;
}

我想要输出:

http://example.org/1201
http://example.org/1202
http://example.org/1203
http://example.org/1204
http://example.org/1205
http://example.org/1206
http://example.org/1207
http://example.org/1208
http://example.org/1209
http://example.org/1210
http://example.org/1211
http://example.org/1212
.......
http://example.org/1220

感谢所有能帮助我的人:D

最佳答案

您可以使用 str_pad()

for ($i=1; $i<=20; $i++){
$i = str_pad($i, 2, "0", STR_PAD_LEFT);
$url = "http://example.org/12".$i."<br />";
echo $url;
}

您还可以使用 sprintf()

for ($i=1; $i<=20; $i++){
$i = sprintf("%02d",$i);
$url = "http://example.org/12".$i."<br />";
echo $url;
}

关于PHP - 列出带有网址的号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20019907/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com