3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array(array(1, 2), array(3, 4), array(5)); function get_combinations($arrays) { $result = array(array()); $count = count($arrays); $first_array = $arrays[0]; if($count > 2) { $array_merg = get_combinations(array_slice($arrays, 1)); } else { $array_merg = $arrays[1]; } $tmp = array(); foreach($first_array as $arele1) { //print_r($arele1); foreach($array_merg as $arele2) { print_r($arele2); if(is_array($arele2)) { echo 'asds'; $tmp[] = array_merge($arele1,$arele2); } else { $tmp[] = array($arele1,$arele2); } print_r($tmp); } } print_r($tmp); return $tmp; } var_dump(get_combinations($a));
Output for git.master, git.master_jit, rfc.property-hooks
5Array ( [0] => Array ( [0] => 3 [1] => 5 ) ) 5Array ( [0] => Array ( [0] => 3 [1] => 5 ) [1] => Array ( [0] => 4 [1] => 5 ) ) Array ( [0] => Array ( [0] => 3 [1] => 5 ) [1] => Array ( [0] => 4 [1] => 5 ) ) Array ( [0] => 3 [1] => 5 ) asds Fatal error: Uncaught TypeError: array_merge(): Argument #1 must be of type array, int given in /in/jUvdv:22 Stack trace: #0 /in/jUvdv(22): array_merge(1, Array) #1 /in/jUvdv(33): get_combinations(Array) #2 {main} thrown in /in/jUvdv on line 22
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
38.04 ms | 402 KiB | 8 Q