3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $option_array[] = array( "name" => "delivery", "options" => array( "sat", "sun") ); $option_array[] = array( "name" => "colour", "options" => array( "red", "blue", "green") ); $option_array[] = array( "name" => "size", "options" => array( "small", "medium", "large") ); $N = 1; foreach ($option_array as $options) $N *= count($options['options']); $all_combinations = array(); for( $i = 0 ; $i < $N ; ++$i ) { $all_combinations[$i] = array(); $q = $i; for( $j = count($option_array)-1 ; 0 <= $j ; --$j ) { $opt = $option_array[$j]; $nopts = count($opt['options']); $all_combinations[$i][$opt['name']] = $opt['options'][$q % $nopts]; $q = floor($q / $nopts); } } print_r( $all_combinations );
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [0] => Array ( [size] => small [colour] => red [delivery] => sat ) [1] => Array ( [size] => medium [colour] => red [delivery] => sat ) [2] => Array ( [size] => large [colour] => red [delivery] => sat ) [3] => Array ( [size] => small [colour] => blue [delivery] => sat ) [4] => Array ( [size] => medium [colour] => blue [delivery] => sat ) [5] => Array ( [size] => large [colour] => blue [delivery] => sat ) [6] => Array ( [size] => small [colour] => green [delivery] => sat ) [7] => Array ( [size] => medium [colour] => green [delivery] => sat ) [8] => Array ( [size] => large [colour] => green [delivery] => sat ) [9] => Array ( [size] => small [colour] => red [delivery] => sun ) [10] => Array ( [size] => medium [colour] => red [delivery] => sun ) [11] => Array ( [size] => large [colour] => red [delivery] => sun ) [12] => Array ( [size] => small [colour] => blue [delivery] => sun ) [13] => Array ( [size] => medium [colour] => blue [delivery] => sun ) [14] => Array ( [size] => large [colour] => blue [delivery] => sun ) [15] => Array ( [size] => small [colour] => green [delivery] => sun ) [16] => Array ( [size] => medium [colour] => green [delivery] => sun ) [17] => Array ( [size] => large [colour] => green [delivery] => sun ) )