参见英文答案 >
Strange behaviour with numbers that have a leading zero 1个
我试图循环遍历从0开始的8位数字.例如,第一个数字是:00000000,我想显示接下来的5个数字.
到目前为止,我设法完成某事.像那样:
$start = 00000000;
$number = 5;
for ($i = $start; $i < $start + $number; $i++) {
$url = sprintf("http://test.com/id/%08d", $i);
echo $url . "\r\n";
}
?>
结果:
http://test.com/id/00000000
http://test.com/id/00000001
http://test.com/id/00000002
http://test.com/id/00000003
http://test.com/id/00000004
这个例子一切都很好,然而,问题始于这样一个例子:
$start = 00050200;
$number = 5;
for ($i = $start; $i < $start + $number; $i++) {
$url = sprintf("http://test.com/id/%08d", $i);
echo $url . "\r\n";
}
?>
for循环产生:
http://test.com/id/00020608
http://test.com/id/00020609
http://test.com/id/00020610
http://test.com/id/00020611
http://test.com/id/00020612
虽然我期待:
http://test.com/id/00050200
http://test.com/id/00050201
http://test.com/id/00050202
http://test.com/id/00050203
http://test.com/id/00050204