"in" is not valid in a foreach statement in php. since you have 2 arrays, you can utilize php's
array_intersect() function.
i haven't tested this code, but this may work for you.
PHP Code:
<?php
$input = "words to be highlighted";
$words = explode(" ",$input);
$string = "i need to have all the words in this string highlighted if they are from the array above";
$search_words = explode(" ",$string);
// set an array of words that match in both arrays
$matched_words = array_intersect($search_words, $words);
// loop through array if it is an array and there is more than 0 items
if (is_array($matched_words) && count($matched_words) > 0) {
// append $msg var in loop
foreach ($matched_words as $each) {
$msg .= "<b>".$each."</b> ";
}
// set $msg error
} else {
$msg = "There were no matches found.";
}
echo($msg);
?>