- print_r: documentation ( source)
- array_keys: documentation ( source)
<?php
$array = [
8 => [
'Blue',
'Red',
'Pink'
],
2 => [
'S',
'M'
]
];
$combinations = [[]];
$comKeys = array_keys($data);
for ($count = 0; $count < count($comKeys); $count++) {
$tmp = [];
foreach ($combinations as $v1) {
foreach ($data[$comKeys[$count]] as $v2)
$tmp[] = $v1 + [$comKeys[$count] => $v2];
}
$combinations = $tmp;
}
print_r($combinations);