3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $root = array_map(function($v) { return 'cat'.$v; }, range(1,10)); //array( 1=>'cat1', 2=>'cat2', 3=>'cat3' ); $child_1 = array_map(function($v) { return 'sub_cat'.$v; },range(1,16)); //array( 1=>'sub_cat1', 2=>'sub_cat2', 3=>'sub_cat3' ); $child_2 = array_map(function($v) { return 'sub_sub_cat'.$v; },range(1,30)); //array( 1=>'sub_sub_cat1', 2=>'sub_sub_cat2', 3=>'sub_sub_cat3' ); function getAllCombinationsArray($root, $child_1, $child_2){ $return = array(); 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($root, $child_1, $child_2));
based on nfJbg