$result = [];
foreach ($data[0]['rates'] as $rate) {
$tmp = [
'rate' => $rate,
'origin' => $data[0]['origin'],
];
rates($tmp, [$data[1], $data[2]]);
}
function rates(array $baseRate, array $nextData): void
{
global $result;
for ($i = 0; $i < count($nextData); ++$i) {
foreach ($nextData[$i]['rates'] as $rate) {
$tmp = [];
$tmp[] = $baseRate;
$tmp[] = [
'rate' => $rate,
'origin' => $nextData[$i]['origin'],
];
for ($j = 0; $j < count($nextData); ++$j) {
if ($i === $j) {
continue;
}
foreach ($nextData[$j]['rates'] as $subRate) {
$tmp[] = [
'rate' => $subRate,
'origin' => $nextData[$j]['origin'],
];
}
}
$result[] = $tmp;
}
}
}
print_r($result);