3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $sentence = "This is a red apple"; $words = array('red','apple'); $ch = implode("|",$words); $pattern = "/($ch)/"; if(preg_match_all($pattern, $sentence,$m)) { echo "yes \n"; print_r($m); }
based on 9issh
Output for 4.3.0 - 5.6.30, hhvm-3.10.1 - 3.22.0, 7.0.0 - 7.2.6
yes Array ( [0] => Array ( [0] => red [1] => apple ) [1] => Array ( [0] => red [1] => apple ) )