This code actually works but it’s a little bit too verbose, i would like to shrink it but i can’t find a solution…
Edit: further explanation: $keywords is an array with a lot of single words extracted from a text. In $text i would like to put al lemmas i can create using adjacent words. Let’s say my original text is “I like green apples”, in $keywords i have “I”,”like”,”green”,”apples”. In $text i will have then “I like”, “I like green”, “I like green apples” …
for ($i=0;$i<=count($keywords);$i++) {
$text[] = $keywords[$i];
$text[] = $keywords[$i]." ".$keywords[$i+1];
$text[] = $keywords[$i]." ".$keywords[$i+1]." ".$keywords[$i+2];
$text[] = $keywords[$i]." ".$keywords[$i+1]." ".$keywords[$i+2]." ".$keywords[$i+3];
$text[] = $keywords[$i]." ".$keywords[$i+1]." ".$keywords[$i+2]." ".$keywords[$i+3]." ".$keywords[$i+4];
$text[] = $keywords[$i]." ".$keywords[$i+1]." ".$keywords[$i+2]." ".$keywords[$i+3]." ".$keywords[$i+4]." ".$keywords[$i+5];
$text[] = $keywords[$i]." ".$keywords[$i+1]." ".$keywords[$i+2]." ".$keywords[$i+3]." ".$keywords[$i+4]." ".$keywords[$i+5]." ".$keywords[$i+6];
}
You will have to use two for-loops in order to create such a list:
This code should work with arbitrary length array.