Why is === faster than == in PHP?
为什么在PHP中===
比==
快?
因为等号运算符==
强制或暂时转换数据类型,以查看它是否与另一个操作数相等,而===
(身份运算符)不需要进行任何转换,因此工作量减少,从而使其更快。
===
不执行类型转换,因此0 == '0'
计算结果为true
,但是0 === '0'
为false
。
First, === checks to see if the two arguments are the same type - so the number 1 and the string '1' fails on the type check before any comparisons are actually carried out. On the other hand, == doesn't check the type first and goes ahead and converts both arguments to the same type and then does the comparison.
Therefore, === is quicker at checking a fail condition
链接地址: http://www.djcxy.com/p/984.html上一篇: 硬头'恢复到以前的承诺?
下一篇: 为什么在PHP中===比==快?