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 { $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 - 7.1.0
Array ( [0] => Array ( [0] => Casa ) [1] => Array ( [0] => perro [1] => Casa ) [2] => Array ( [0] => abad [1] => Casa ) [3] => Array ( [0] => abad [1] => perro [2] => Casa ) )