Recursive approach:
function iterate($words) {
if(($total = count($words)) > 0) {
$str = '';
for($i = 0; $i < $total; $i++ ) {
$str .= ' ' . $words[$i];
echo $str . PHP_EOL;
}
array_shift($words);
iterate($words);
}
}
$text = "Today is a great day.";
$words = str_word_count($text, 1);
iterate($words);
The above will only consider words. It will not remove duplicates. Numbers are not words and punctuation ain't either. With the given test sentence of five words, the recursive approach performs neglectably faster than the array_splice solution. However, this increases significantly with each additional word. A quick benchmark on my machine with a ten word sentence finished in almost half the time.
Disclaimer: Isolated Benchmarks depend on a number of factors and may produce different results on different machines. If anything, they can give an indicator about code performance (often in the realms of micro-optimzations), but nothing more.