$text = 'давайте выражаться культурно';
$arWords = explode(' ',$text);
function implodeAndNest($arWords){
$arResult = array();
foreach($arWords as $wordNum => $word){
if($wordNum == 0){
$arResult[] = implode(' ',array_slice($arWords,$wordNum));
}else{
$arResult[] = array(implode(' ',array_slice($arWords,0,$wordNum)) => implode(' ',array_slice($arWords,$wordNum)));
}
}
return $arResult;
}
$arResult = array();
foreach($arWords as $wordNum => $word){
if($wordNum == 0){
$arResult[] = implodeAndNest(array_slice($arWords,$wordNum));
}else{
$arResult[] = array(implode(' ',array_slice($arWords,0,$wordNum)) => implodeAndNest(array_slice($arWords,$wordNum)));
}
}
echo '<pre>';
print_r($arResult);
echo '</pre>';
$input = 'ololo 123 test pif paf';
$array = explode(' ', $input); // ["ololo", "123", "test", "pif", "paf"]
$result = array();
$length = count($array);
for ($i = 0; $i+1 < $length; $i++) {
for ($j = $i+1; $j < $length; $j++) {
$result[] = $array[$i] . ' ' . $array[$j];
}
}
var_dump($result); // ["ololo 123", "ololo test", "ololo pif", "ololo paf", "123 test", "123 pif", "123 paf", "test pif", "test paf", "pif paf"]