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
https://forums.phpfreaks.com/topic/201470-pulling-out-all-poss-combinations/
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 />";
                    }
            }
    }

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.