gpt4 book ai didi

php - 为什么 $a += 3 比 $a = $a + 3 执行得更快?

转载 作者:可可西里 更新时间:2023-11-01 12:53:25 25 4
gpt4 key购买 nike

PHP manual指出:

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.

我曾经认为 $a += 3 只是 $a = $a + 3 的语法糖,因此它们应该相等 在所有方面。

为什么 $a += 3$a = $a + 3 执行得更快?

最佳答案

$a = $a + 3 在临时内存空间中将$a加3,然后将结果赋值给$a;而 $a += 3 将 3 直接加到 $a 上;所以区别是临时存储的几个字节的内存,加上一个赋值

关于php - 为什么 $a += 3 比 $a = $a + 3 执行得更快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17493164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com