如何将数组中的值与字符串匹配?
我使用一个数组来修复文本中的拼写错误。我想回收这个数组来匹配它的值。
$fruitNameFixes = array(
'/bann?ann?a/i' => 'banana',
'/app?e?le?/i' => 'apple',
);
$str = "I like bananas and oranges!";
if( preg_match('/(banana|apple)/i', $str) ) { //add $fruitNameFixes values
echo "He likes fruits from the fruitNameFixes array";
} else {
echo "Nope, he doesn't like fruits from the fruitNameFixes array";
}