PHP中的==和===运算符 [英] == and === operators in php

查看:108
本文介绍了PHP中的==和===运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个永远是字符串的变量.

Let's say I have a variable that will always be a string.

现在使用以下代码:

if($myVar === "teststring")

注意:$myVar将始终是字符串,所以我的问题是

Note: $myVar will always be a string, so my questions is

使用===(身份)或==(相等)哪个更快/最好?

Which is quicker/best, using === (indentity) or the == (equality)?

推荐答案

测试身份总是更快,因为PHP不必键入Juggle即可评估比较.但是,我会说速度差异在纳秒级范围内,可以忽略不计.

Testing for identity is always faster, because PHP does not have to Type Juggle to evaluate the comparison. However, I'd say the speed difference is in the realms of nanoseconds and totally neglectable.

相关阅读:

  • PHP type comparison tables
  • Type Juggling

这篇关于PHP中的==和===运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆