Generate the set of all X-digit numbers [duplicate]
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 ;)
精彩评论