-1

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.

MarathonStudios
  • 3,983
  • 10
  • 40
  • 46

2 Answers2

6

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

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
4
for ($i=0; $i<=9999999; $i++) {
  echo sprintf("%07d", $i) . '<br / >';
}

This might break your browser though ;)

Alec
  • 9,000
  • 9
  • 39
  • 43