i found a solution...not mine.
the pc_next_permutation function gives all permutations of a variable number of arrays.
the showCombinations function outputs the variations of the arrays elements at each permutation.
i'd be interested to see your solution though. thanks.
function showCombinations($string, $traits, $i)
{
if ($i >= count($traits))
echo trim($string) . "<br/>";
else
{
foreach ($traits[$i] as $trait)
showCombinations("$string $trait", $traits, $i + 1);
}
}
function pc_next_permutation($p, $size) {
// slide down the array looking for where we're smaller than the nextguy
for ($i = $size - 1; $p[$i] >= $p[$i+1]; --$i) { }
// if this doesn't occur, we've finished our permutations
// the array is reversed: (1, 2, 3, 4) => (4, 3, 2, 1)
if ($i == -1) { return false; }
// slide down the array looking for a bigger number than what we foundbefore
for ($j = $size; $p[$j] <= $p[$i]; --$j) { }
// swap them
$tmp = $p[$i]; $p[$i] = $p[$j]; $p[$j] = $tmp;
// now reverse the elements in between by swapping the ends
for (++$i, $j = $size; $i < $j; ++$i, --$j) {
$tmp = $p[$i]; $p[$i] = $p[$j]; $p[$j] = $tmp;
}
return $p;
}
$set = array
(
array('red', 'blue', 'green'),
array('small', 'medium'),
array('car', 'truck', 'van')
);
$size = count($set) - 1;
$perm = range(0, $size);
$j = 0;
do {
foreach ($perm as $i) { $perms[$j][] = $set[$i]; }
} while ($perm = pc_next_permutation($perm, $size) and ++$j);
foreach ($perms as $p) {
showCombinations('', $p, 0);
}