3v4l.org

run code in 300+ PHP versions simultaneously
<?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 ($array[$comKeys[$count]] as $v2) $tmp[] = $v1 + [$comKeys[$count] => $v2]; } $combinations = $tmp; } print_r($combinations);

preferences:
52.89 ms | 402 KiB | 5 Q