- array_splice: documentation ( source)
- array_slice: documentation ( source)
- print_r: documentation ( source)
- array_merge: documentation ( source)
<?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;
}
}