tags:

views:

34

answers:

2

I want to iterate through all 5 character combinations of 0-9, a-z.

I worked it at to be around 52 millions combinations. How can I programatically iterate through all the possibilities in PHP? - like counting up or something?

+3  A: 

Use base_convert($n, 10, 36) counting from 0 to 36**5-1, and pad with zeroes via sprintf().

Ignacio Vazquez-Abrams
Quick blog post on padding numbers with leading zeroes: http://www.alexanderdickson.com/blog/2010/03/formatting-a-number-with-leading-zeroes-in-php/ **note:** link is to my own blog
alex
there's no need to pre-calculate 36^5, just `while($x != 'zzzzz')...`
stereofrog
Do note that `base_convert()` returns a string, therefore you should use the `%s` format specifier.
Ignacio Vazquez-Abrams
A: 

I tried to provide an answer, but kept getting stuck with it.

So I'll post maybe the only useful portion. To get a list of all those chars easily, the following should do the trick.

$pool = range(0, 9) + range('a', 'z');
alex