douchi0471 2015-11-29 13:58
浏览 36
已采纳

str_replace函数如何工作?

I'm trying to understand the str_replace function.

Code:

$a = array(1,8,7,5);
$b = array(3,7,11,6);
$str = '879';
$c = str_replace($a, $b , $str);
echo $c;

Output:

11119

I don't understand the output. Can someone explain how the str_replace function works?

  • 写回答

2条回答 默认 最新

  • doumo1807831 2015-11-29 14:04
    关注

    str_replace replaces pair of values from provided arrays $a, $b. And does it in order, so str_replace($a, $b , $str) means:

    replace 1 to 3,
    then replace 8 to 7,
    then replace 7 to 11
    and finally replace 5 to 6.
    

    So, let's go:

    • input 879, replace 1 to 3, output 879
    • input 879, replace 8 to 7, output 779
    • input 779, replace 7 to 11, output 11119
    • input 11119, replace 5 to 6, output 11119
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器