您可以使用带有 str_replace() 的数组:
$array_from = array ('from1', 'from2');
$array_to = array ('to1', 'to2');
$text = str_replace ($array_from, $array_to, $text);
但是如果你有关联数组呢?
$array_from_to = array (
'from1' => 'to1';
'from2' => 'to2';
);
如何将它与 str_replace() 一起使用?
速度很重要——阵列足够大。
最佳答案
$text = strtr($text, $array_from_to)
顺便说一句,那仍然是一个一维“数组”。
关于php - str_replace() 与关联数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2399286/