imperium2335 Posted May 16, 2011 Share Posted May 16, 2011 Hi, What would be the best way to generate an incremental 4 letter string that would start off like this: 0A, 0B, 0C ....4AB, 4AC, 4AD....50A, 50B...53AA,53AB...7A0,7A1,7A2...etc etc and stop at something like 9999 or ZZZZ? So I could get all possible combinations of letters and numbers really. Quote Link to comment Share on other sites More sharing options...
requinix Posted May 16, 2011 Share Posted May 16, 2011 Do you want an array of all of them? At once? At 0-9 A-Z that's more than 1.7 million combinations. There's a risk that PHP will run out of memory before it can grab them all. Quote Link to comment Share on other sites More sharing options...
imperium2335 Posted May 16, 2011 Author Share Posted May 16, 2011 Hi, RAM isn't a problem for me, but what I want to happen is for it to go through every possible combination one by one. I thought of an array but there will be so many like you said, 1.7mil! Once they have gone through the loop they don't need to be stored. As an example: while($combination != $thelastpossiblecombination) { echo $combination ; } Quote Link to comment Share on other sites More sharing options...
requinix Posted May 16, 2011 Share Posted May 16, 2011 Well, there's always the brute-force solution: $chars = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $_code = " "; for ($a = 0; $a for ($b = 0; $b for ($c = 1; $c for ($d = 1; $d $code = ltrim($_code); // ... }}}} Quote Link to comment Share on other sites More sharing options...
imperium2335 Posted May 16, 2011 Author Share Posted May 16, 2011 thanks! That's exactly what I wanted That's a lot of combinations Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.