3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array('A' => array(1, 2), 'B' => array(3, 4), 'C' => array(5)); function get_combinations($arrays) { $result = array(array()); foreach ($arrays as $property => $property_values) { $tmp = array(); foreach ($result as $result_item) { foreach ($property_values as $property_value) { $tmp[] = array_merge($result_item, array($property => $property_value)); } } $result = $tmp; } return $result; } var_dump(get_combinations($a));

preferences:
36.52 ms | 402 KiB | 5 Q