douqi0090 2013-07-05 16:18
浏览 34

为什么$ a + = 3的执行速度比$ a = $ a + 3快?

PHP manual states that:

Adding 3 to the current value of $a can be written '$a += 3'. This means exactly "take the value of $a, add 3 to it, and assign it back into $a". In addition to being shorter and clearer, this also results in faster execution.

I used to think that $a += 3 is merely syntax sugar for $a = $a + 3 and thus they should be equal in all respects.

Why does $a += 3 result in faster execution compared to $a = $a + 3?

  • 写回答

3条回答 默认 最新

  • duandong9195 2013-07-05 16:22
    关注

    $a = $a + 3 adds 3 to $a in a temporary memory space, then assigns the result to $a; while $a += 3 adds 3 directly to $a; so the difference is a few bytes of memory for temporary storage, plus an assignment

    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程