Page 1 of 1

Pulling out all possible combinations

Posted: Wed May 12, 2010 4:38 am
by freelance84
Road Possible options
1 1, 2 or 3
2 1, 2 or 3
3 1, 2 or 3


Does anyone know how I would tell php to pull all the possible combinations out if road = $road and Possible options = $pso?

Would it be a case of using a series of for loops inside each other?

Quite stumped on this one as I've never seen or done anything like this before.

Thanks in advance if you can help

Re: Pulling out all possible combinations

Posted: Wed May 12, 2010 4:57 am
by freelance84
I can't believe it but i think i've done it:

$count1 = count array $pso1
$count2 = count array $pso2
$count3 = count array $pso3

Code: Select all

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 />";
                    }
            }
    }