函数原型类似于relace(str,arr1,arr2),作用是:在str查找数组arr1中的字符串,并替换成数组arr2中对应的字符串,并且不会出现重复替换的现象(即:假设arr2[0]中含有arr1[1],最终结果arr2[0]中的arr1[1],不会被替换)
str_replace基本已经具备你说的这个功能。
$phrase = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy = array("pizza", "beer", "ice cream");
$newphrase = str_replace($healthy, $yummy, $phrase);
输出替换成yummy数组的句子。
You should eat pizza, beer, and ice cream every day
温馨提示:答案为网友推荐,仅供参考