I need to order an unknown array of keywords by the order they occur in a text string.
// random order of unknown values
$keywords = array( "orange", "green apple", "banana" );
// ordered occurrences
$text = "This is text where the keywords can appear as well like green apple trees.
Then follows text where the keywords are in order and surrounded by unique syntax.
((randomly ordered keywords))
((foo))
((banana))
((orange))
((baz))
((green apple))
((baz))
";
// reorder keywords
// maybe preg_match( "/.+\({2}(".$keywordItem.")\).*/", $text, $matches )
// ...
// Order should be banana, orange, green apple
print_r( $keywords );
The solution may include ´preg_match`, but I don't know where to start.