I want to extract two consecutive words starting from each word in a string.
$string = "This is my test case for an example."
If I explode on each space, I get every word individually, but I don’t want that.
[
'This',
'is',
'my',
'test',
'case',
'for',
'an',
'example.'
];
What I want is to get each word and its next word including the delimiting space.
Desired output:
[
'This is'
'is my'
'my test'
'test case'
'case for'
'for an',
'an example.'
]
this will provide the output you’re looking for
Wrapped in a function: