Jump to content

Pulling out all poss combinations


freelance84

Recommended Posts

Ok I have the following:

 

Road  Possible Options

  1          1, 2, 3

  2          1, 2, 3

  3          1, 2, 3

 

The user must use road 1, then road 2 then road 3. I want to be able to tell php to show all the possible combinations of the above. i.e:

 

111, 112, 113, 211, 212, 213, 221, 222.... etc etc.

 

If road = $road    and possible options = $pso

 

 

Any ideas? I'm stumped, never done this before, can do it in my head obviously but no idea how to tell a computer how to do it.

 

Thanks in advance for any help

Link to comment
Share on other sites

I can't believe it but i think i've done it:

 

$count1 = count array $pso1

$count2 = count array $pso2

$count3 = count array $pso3

 

for($a = 1 ; $a < $count1 ; ++$a)
    {
        for($b = 1 ; $b <$count2;++$b)
           {
                 for($c = 1 ; $c < $count3 ; ++$c)
                    {
                         echo $pso[$a].$pso[$b].$pso[$c] "<br />";
                    }
            }
    }

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.