3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function getAllCombinationsArray(){ $return = array(); $root = array( 1=>'cat1', 2=>'cat2', 3=>'cat3' ); $child_1 = array( 1=>'sub_cat1', 2=>'sub_cat2', 3=>'sub_cat3' ); $child_2 = array( 1=>'sub_sub_cat1', 2=>'sub_sub_cat2', 3=>'sub_sub_cat3' ); foreach($root as $fk => $fv){ foreach($child_1 as $ck => $cv){ $cid = $fk.'_'.$ck; $cname = $fv.' -> '.$cv; foreach($child_2 as $ck2 => $cv2){ $id = $cid.'_'.$ck2; $name = $cname.' -> '.$cv2; $return[$id] = $name; } } } return $return; } print_r(getAllCombinationsArray());
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.13.2, 7.0.0 - 7.1.0
Array ( [1_1_1] => cat1 -> sub_cat1 -> sub_sub_cat1 [1_1_2] => cat1 -> sub_cat1 -> sub_sub_cat2 [1_1_3] => cat1 -> sub_cat1 -> sub_sub_cat3 [1_2_1] => cat1 -> sub_cat2 -> sub_sub_cat1 [1_2_2] => cat1 -> sub_cat2 -> sub_sub_cat2 [1_2_3] => cat1 -> sub_cat2 -> sub_sub_cat3 [1_3_1] => cat1 -> sub_cat3 -> sub_sub_cat1 [1_3_2] => cat1 -> sub_cat3 -> sub_sub_cat2 [1_3_3] => cat1 -> sub_cat3 -> sub_sub_cat3 [2_1_1] => cat2 -> sub_cat1 -> sub_sub_cat1 [2_1_2] => cat2 -> sub_cat1 -> sub_sub_cat2 [2_1_3] => cat2 -> sub_cat1 -> sub_sub_cat3 [2_2_1] => cat2 -> sub_cat2 -> sub_sub_cat1 [2_2_2] => cat2 -> sub_cat2 -> sub_sub_cat2 [2_2_3] => cat2 -> sub_cat2 -> sub_sub_cat3 [2_3_1] => cat2 -> sub_cat3 -> sub_sub_cat1 [2_3_2] => cat2 -> sub_cat3 -> sub_sub_cat2 [2_3_3] => cat2 -> sub_cat3 -> sub_sub_cat3 [3_1_1] => cat3 -> sub_cat1 -> sub_sub_cat1 [3_1_2] => cat3 -> sub_cat1 -> sub_sub_cat2 [3_1_3] => cat3 -> sub_cat1 -> sub_sub_cat3 [3_2_1] => cat3 -> sub_cat2 -> sub_sub_cat1 [3_2_2] => cat3 -> sub_cat2 -> sub_sub_cat2 [3_2_3] => cat3 -> sub_cat2 -> sub_sub_cat3 [3_3_1] => cat3 -> sub_cat3 -> sub_sub_cat1 [3_3_2] => cat3 -> sub_cat3 -> sub_sub_cat2 [3_3_3] => cat3 -> sub_cat3 -> sub_sub_cat3 )