fork download
  1. <?php
  2.  
  3. $matchWords = array("red","blue","azure");
  4. $sentence = "Red fox met a blue whale";
  5.  
  6. $result = array_intersect(
  7. $matchWords,
  8. str_word_count(strtolower($sentence), 1)
  9. );
  10.  
  11. var_dump($result);
  12.  
Success #stdin #stdout 0.01s 24448KB
stdin
Standard input is empty
stdout
array(2) {
  [0]=>
  string(3) "red"
  [1]=>
  string(4) "blue"
}