$text = 'Шла саша по шоссе и сосала сушку';
$arWords = explode(' ',$text);
function implodeAndNest($arWords,$firstElement = null){
$arResult = array();
foreach($arWords as $wordNum => $word){
if($wordNum == 0){
$result = array(implode(' ',array_slice($arWords,$wordNum)));
}else{
$result = array(implode(' ',array_slice($arWords,0,$wordNum)),implode(' ',array_slice($arWords,$wordNum)));
}
if(isset($firstElement))
$result = array_merge(array($firstElement),$result);
$arResult[] = $result;
}
return $arResult;
}
$arResult = array();
foreach($arWords as $wordNum => $word){
if($wordNum == 0){
$arResult = implodeAndNest(array_slice($arWords,$wordNum));
}else{
$arResult = array_merge($arResult,array_values(implodeAndNest(array_slice($arWords,$wordNum),implode(' ',array_slice($arWords,0,$wordNum)))));
}
}
// удаляем лишние результаты
$arResult = array_values(array_map("unserialize", array_unique(array_map("serialize", $arResult))));
echo '<pre>';
print_r($arResult);
echo '</pre>';