开发者

Generate the set of all X-digit numbers [duplicate]

This question already has answers here: How to pad single-digit numbers with 开发者_StackOverflow社区a leading 0 (7 answers) Closed 10 months ago.

Basically, I need to generate a list of all seven-digit numbers (for example, 1461979) from 0000000 to 9999999. I know there are 10^7 of them (ten million), but I can't think of an efficient function to output them. I'm sure there's a generic function out there that can do it - preferably in PHP, but I can port it if need be.


Loop from 0 to 9999999 and use one of the dozens of methods for zero-filling a number, such as printf("%07d", $val).


for ($i=0; $i<=9999999; $i++) {
  echo sprintf("%07d", $i) . '<br / >';
}

This might break your browser though ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜