<?php
$a = [
'color' => ['red', 'blue', 'orange'],
'size' => ['10-12', '12-14', '13-13'],
'somekey' => ['val1', 'val2', 'val3'],
];
function addValue(&$arr, $key, $val)
{
if (!count($arr)) {
$arr[] = [$key => $val];
return;
}
foreach($arr as $num => $values) {
$arr[$num][$key] = $val;
}
}
$b = [];
foreach($a as $key => $values) {
$copyB = $b;
$newB = [];
foreach($values as $value) {
$currentB = $copyB;
addValue($currentB, $key, $value);
$newB = array_merge($newB, $currentB);
}
$b = $newB;
}
print_r($b);