I know how to split my input string on spaces, but I need to generate an array of values where each element contains the previous string PLUS the next available word.
$str = "a nice and sunny day today";
$split = explode(' ', $str);
How could I possibly be left with an array that looks like the following:
$new[0] = 'a';
$new[1] = 'a nice';
$new[2] = 'a nice and';
$new[3] = 'a nice and sunny';
Instead of manually doing this
$new[] = $split[0];
$new[] = $split[0] . $split[1];
$new[] = $split[0] . $split[1] . $split[2];
$new[] = $split[0] . $split[1] . $split[2] . $split[3];
You can probably see the pattern that's happening.
Because this can happen for up to around 15 words, I'm seeking a shorter and dynamic way of doing this using a foreach/some kind of function.