3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = array('a', 'b', 'c'); function depth_picker($arr, $temp_string, &$collect) { if ($temp_string != "") $collect []= $temp_string; for ($i=0; $i<sizeof($arr);$i++) { $arrcopy = $arr; $elem = array_splice($arrcopy, $i, 1); // removes and returns the i'th element if (sizeof($arrcopy) > 0) { depth_picker($arrcopy, $temp_string ."" . $elem[0], $collect); } else { $collect []= $temp_string. " " . $elem[0]; } } } $collect = array(); depth_picker($array, "", $collect); print_r($collect);
based on 9G5c9
Output for 4.3.0 - 7.2.0
Array ( [0] => a [1] => ab [2] => ab c [3] => ac [4] => ac b [5] => b [6] => ba [7] => ba c [8] => bc [9] => bc a [10] => c [11] => ca [12] => ca b [13] => cb [14] => cb a )