Pulling out all possible combinations

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
freelance84
Forum Newbie
Posts: 8
Joined: Thu Apr 29, 2010 6:32 pm

Pulling out all possible combinations

Post 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
freelance84
Forum Newbie
Posts: 8
Joined: Thu Apr 29, 2010 6:32 pm

Re: Pulling out all possible combinations

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