lundi 23 février 2015

Fastest way to link words in PHP array

I have a sentence in a simple PHP string:



$myString = "This is a test.";


I want an array that contains all possible connections between two words, or two groups of words, as follows (whitespace as a delimiter):



$myArray = [
["This", "is"],
["This", "is a"],
["This", "is a test."],
["This is", "a"],
["This is", "a test."],
["This is a", "test."],
["is", "a"],
["is", "a test."],
["is a", "test."],
["a", "test."]
];


It must run as fast as possible, hopefully in a single scan of the input string.


Aucun commentaire:

Enregistrer un commentaire