Fog Juice Posted June 30, 2009 Share Posted June 30, 2009 Hello, Suppose the following: $wh1 = rand(1, 16); $wh2 = rand(1, 16); $wh3 = rand(1, 16); I want to generate every combination of $wh1, $wh2, and $wh3. There will be 4,096 different combination but I want to print them out in a list for a little app I'm making. Before I even get started on doing this, can someone suggest what might be a better way to do this? I enjoy php but my math skills are not so great. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/164289-solved-generating-every-combination-of-3-wheels-from-1-to-16/ Share on other sites More sharing options...
Daniel0 Posted June 30, 2009 Share Posted June 30, 2009 $result = array(); for ($wh1 = 1; $wh1 <= 16; ++$wh1) { for ($wh2 = 1; $wh2 <= 16; ++$wh2) { for ($wh3 = 1; $wh3 <= 16; ++$wh3) { $result[] = array($wh1, $wh2, $wh3); } } } Quote Link to comment https://forums.phpfreaks.com/topic/164289-solved-generating-every-combination-of-3-wheels-from-1-to-16/#findComment-866652 Share on other sites More sharing options...
Fog Juice Posted June 30, 2009 Author Share Posted June 30, 2009 $result = array(); for ($wh1 = 1; $wh1 <= 16; ++$wh1) { for ($wh2 = 1; $wh2 <= 16; ++$wh2) { for ($wh3 = 1; $wh3 <= 16; ++$wh3) { $result[] = array($wh1, $wh2, $wh3); } } } damn you, I figured it out and was just about to post solution and close the thread but you beat me to it. lol. I thought it would be something more complicated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/164289-solved-generating-every-combination-of-3-wheels-from-1-to-16/#findComment-866660 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.