Home > Backend Development > PHP Tutorial > 一个0开头的数据循环累加的问题

一个0开头的数据循环累加的问题

WBOY
Release: 2016-06-23 13:42:03
Original
872 people have browsed it

今天要批量生成一批合同号,遇到问题了,比如说
start=0066812~end=0066818

for ($start;$start 除了0066812之外,后面的全将00给去掉了,请问有什么方法可以保留住0的??


回复讨论(解决方案)

$start = 66812;$end = 66818;for ($start;$start<=$end;$start++){  $s = sprintf('%07d', $start);  echo $s . '<br>';}
Copy after login
Copy after login
0066812006681300668140066815006681600668170066818
Copy after login
Copy after login

$start = 66812;$end = 66818;for ($start;$start<=$end;$start++){  $s = sprintf('%07d', $start);  echo $s . '<br>';}
Copy after login
Copy after login
0066812006681300668140066815006681600668170066818
Copy after login
Copy after login


赋值的时候一定要是
$start = 0066812;
$end = 0066818;
前边有两个0
因为还有种可能是009999到010000,反正09过了就是10,前边就不是两个0了

有什么区别吗?

$start = '0066812';$end = '0066818'; for ($start;$start<=$end;$start++){  $s = sprintf('%07d', $start);  echo $s . '<br>';}
Copy after login
Copy after login
0066812
0066813
0066814
0066815
0066816
0066817
0066818


但是如果写作 $start = 0066812;
那就是八进制数,全完蛋了

有什么区别吗?

$start = '0066812';$end = '0066818'; for ($start;$start<=$end;$start++){  $s = sprintf('%07d', $start);  echo $s . '<br>';}
Copy after login
Copy after login
0066812
0066813
0066814
0066815
0066816
0066817
0066818


但是如果写作 $start = 0066812;
那就是八进制数,全完蛋了



谢谢,讲得非常好,大师太好了
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template