$result = [
'A' => [1, 2, 3],
'B' => [10, 20, 30],
'C' => [100, 200, 300],
'D' => ['a', 'b', 'c', 'd'],
];
[1, 10, 100, 'a'];
[2, 10, 100, 'a'];
[3, 10, 100, 'a'];
[1, 20, 100, 'a'];
[2, 20, 100, 'a'];
...
[3, 30, 300, 'd'];
function deployValues(&$base, $values) {
$newBase = [];
foreach ($values as $i => $value) {
foreach ($base as $j => $baseValue) {
$orig = is_array($baseValue) ? $baseValue : [$baseValue];
array_push($orig, $value);
$newBase[] = $orig;
}
}
$base = $newBase;
}
$r = [
'A' => [1, 2, 3],
'B' => [10, 20, 30],
'C' => [100, 200, 300],
'D' => ['a', 'b', 'c', 'd'],
];
$x = null;
foreach ($r as $c) {
if ($x === null) {
$x = $c;
} else {
deployValues($x, $c);
}
}
print_r($x);