php在句子之间找到相同的单词

How to get same words between sentences? here are some cords witch from pdo mysql query.

if($q->rowCount()>0){
 foreach($q->fetchAll(PDO::FETCH_ASSOC) as $r){
   $t=$r['text'];
   $e=explode(' ',$t);
   //array_intersect();
 }
}
//from $r['text'] query get:
//Israel breaks through the Google Glass ceiling
//Google Glass wearers getting used to curious stares
//Airlines start to look through the Google Glass

from these 3 sentences, the same words should be get Google Glass, but how to write codes in my pdo mysql query case? thanks

You should concatenate all the sentences that you get to a variable and then pass the concatenated variable to explode function, then pass the exploded array to array_count_values($array).

Step 1:

Concatenate the Sentences to a single variable so you will have

$concat = "Israel breaks through the Google Glass ceiling
Google Glass wearers getting used to curious stares
Airlines start to look through the Google Glass";

in a single variable.

Step 2:

pass the $concat to $array = explode(" ",$concat);

step 3:

The exploded variable would be an array you pass that to array_count_values($array);

print_r(array_count_values($array));

so you would get output like

Array
(
   [Google ] => 3
   [Glass] => 2
   etc...
)

So the key with count more than 1 are duplicate and you could print those keys easliy

$youText= explode(' ',$youText);
$youText= array_flip($youText);

check you condition

if (isset($youText[$word])){
      doSomething();
  }

another way

$searchMyWord = $_GET['search'];
    $searchMyWord = preg_quote($searchMyWord);

    if (preg_match("/\b$searchMyWord\b", $input) {
      echo "$input has the word $searchMyWord";
    }