3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $a = array('A' => array(1, 2), 'B' => array(3, 4), 'C' => array(5)); function get_combinations($arrays) { $result = array(array()); $count = count($arrays); if($count > 2) { $array_merg = get_combinations(array_slice($arrays, 1)); } else { $array_merg = $arrays[1]; } $tmp = array(); foreach($arrays[0] as $arele1) { foreach($array_merg as $arele2) { if(is_array($arele2)) { $tmp[] = array_unshift($arele2,$arele1); } else { $tmp[] = array($arele1,$arele2); } } } return $tmp; } var_dump(get_combinations($a));
Output for 5.3.0 - 7.1.0
Notice: Undefined offset: 1 in /in/HNeZW on line 12 Notice: Undefined offset: 0 in /in/HNeZW on line 15 Warning: Invalid argument supplied for foreach() in /in/HNeZW on line 15 Notice: Undefined offset: 0 in /in/HNeZW on line 15 Warning: Invalid argument supplied for foreach() in /in/HNeZW on line 15 array(0) { }
Output for 5.2.1 - 5.2.17
Notice: Undefined offset: 1 in /in/HNeZW on line 12 Notice: Undefined offset: 0 in /in/HNeZW on line 15 Warning: Invalid argument supplied for foreach() in /in/HNeZW on line 15 Notice: Undefined offset: 0 in /in/HNeZW on line 15 Warning: Invalid argument supplied for foreach() in /in/HNeZW on line 15 array(0) { }
Output for 4.3.0 - 4.3.10, 4.4.0 - 5.2.0
Notice: Undefined offset: 1 in /in/HNeZW on line 12 Warning: Invalid argument supplied for foreach() in /in/HNeZW on line 15 Warning: Invalid argument supplied for foreach() in /in/HNeZW on line 15 array(0) { }
Output for 4.3.11
Notice: Undefined offset: 1 in /in/HNeZW on line 12 array(0) { }