gpt4 book ai didi

php - 什么更快?如果()返回;否则返回;或者如果()返回;返回;

转载 作者:可可西里 更新时间:2023-11-01 13:08:17 27 4
gpt4 key购买 nike

在编码时,我问了自己这个问题:

这样更快吗:

if(false) return true;
else return false;

比这个?

if(false) return true;
return false;

当然,如果有差异那是荒谬的,但我的好奇心不会消失,直到我知道 :D

最佳答案

只是:

return !false;

现实生活中的例子

return !$this->isSth();

// Not

if ($this->isSth) {
return false;
} else {
return true;
}

性能在这里并不重要 - 每个解决方案都非常快,无需优化。记住 Donald Knuth 的话:

Premature optimization is the root of all evil

关于php - 什么更快?如果()返回;否则返回;或者如果()返回;返回;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4465046/

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