OK I found the solution:
A. right, I made an associative arrays of all my attributes:
Array (
[0] => Array
(
[0] => 20
[1] => 21
)
[1] => Array
(
[0] => 61
[1] => 62
[2] => 63
)
)
B. then I recursively create the whole possible variations:
function buildVariants($arrays, $i = 0) {
if (!isset($arrays[$i])) {
return array();
}
if ($i == count($arrays) - 1) {
return $arrays[$i];
}
// get combinations from subsequent arrays
$tmp = $this->buildVariants($arrays, $i + 1);
$result = array();
// concat each array from tmp with each element from $arrays[$i]
foreach ($arrays[$i] as $v) {
foreach ($tmp as $t) {
$result[] = is_array($t) ? array_merge(array($v), $t) : array($v, $t);
}
}
return $result;
}
C. then I add it to tables in this structure: