【发布时间】:2021-08-18 00:40:57
【问题描述】:
字符串替换两个数组只替换第一次出现的每个数组
$text = 'The Book has read by Dog and Cat then Book show Apple not Dog';
$array1 =array('1','2','3','4','5','6');
$array2=array('Book','Dog','Cat','Book','Apple','Dog');
echo str_replace($array2, $array1, $text);
输出已经
The 1 has read by 2 and 3 then 1 show 5 not 2
但需要输出
The 1 has read by 2 and 3 then 4 show 5 not 6
字符串替换数组第 4 和第 6 不能替换它已经重复它必须是第 1 次出现只能替换可能?
【问题讨论】: