需要$new_string
输出New York NY
但我得到New York NY York NY
$phrases = array("New York NY","York NY","Wyoming MI","Wyoming Minnesota");
$string = ("I live in New York NY");
$matches = array();
foreach($phrases as $phrase) {
if(stripos($string,$phrase) !== false){
$matches[] = $phrase;
}
}
$new_string = implode(" ",$matches);
echo $new_string;