3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $words=array("Casa", "perro", "abad"); print_r(getAllWordCombos($words)); function getAllWordCombos($words) { if (count($words)==1) return array($words); else if (count($words)==2) return array(array($words[0], $words[1]), array($words[1],$words[0])); else { $ret=array(); foreach($words as $i=>$firstword) { $cwords=array_slice($words,0); array_splice($cwords,$i); $combos=getAllWordCombos($cwords); $head=array($firstword); foreach ($combos as $combo) { $ret[]=array_merge($head,$combo); } } return $ret; } }
Output for 4.3.0 - 5.6.25, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [0] => Array ( [0] => perro [1] => Casa ) [1] => Array ( [0] => abad [1] => Casa [2] => perro ) [2] => Array ( [0] => abad [1] => perro [2] => Casa ) )