3种不同的比较,=,==,===
=
,==
和===
之间有什么区别?
我认为使用一个=
是声明一个变量,而==
是用于比较条件,最后=====
是用于比较声明的值变量。
What is the difference between =
, ==
, and ===
?
I think using one =
is to declare a variable while ==
is for a comparison condition and lastly ===
is for comparing values of declared variables.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您有
=
分配运算符,==
'等于'比较操作员 和==================
“相同”比较操作员。有关
==
和====
的更多信息,以及要使用的情况,请查看文档。You have
=
the assignment operator,==
the 'equal' comparison operator and===
the 'identical' comparison operator.For more info on the need for
==
and===
, and situations to use each, look at the docs.=
是分配操作员==
是比较操作员(检查是否
两个变量具有相等的值)
===
是相同的比较操作员(检查两个变量是否
具有相等的值,相同
类型)。
=
is the assignment operator==
is the comparison operator (checks if
two variables have equal values)
===
is the identical comparisonoperator (checks if two variables
have equal values and are of the same
type).
=分配运算符
==检查两个变量是否具有相同的值
===检查两个变量是否具有相同的值,并且它们的类型是否相同
= assignment operator
== checks if two variables have the same value
=== checks if two variables have the same value AND if their types are the same
=操作员将值分配给变量
$六= 6;值6分配给变量$六
==运算符检查两个变量的值是否相等,并且主要在诸如if语句
===运算符等条件下使用,类似于==(检查值等于值),并且还检查两个是否相同数据类型
//此处$ a是类型int类型,而$ b是字符串类型。所以在这里输出
The = operator assigns the value to a variable
$six = 6; value 6 is assigned to variable $six
== operator check if the value of both variables is equal and mostly used in conditions like if statements
=== operator similar to == (check if the value equals) and also check if both of same data type
// here $a is of type int whereas $b is of type string. So here the output
对于高级PHP用户,了解
==
和=====
之间的差异,并且“与==
进行比较速度更快?===
当我确定两个操作数都是相同类型时吗?”简短而一般的答案是:在这种情况下,使用
===
没有性能提高,因此您可能应该使用==
。。对于有兴趣对其进行基准测试的人,您可以使用以下代码我编写了临时的代码,并尝试
$ a
和$ b
$ a :注意:比较:仅当每个“第一次尝试”都非常接近其“第二次尝试”时有效。如果它们有很大的不同,则意味着处理器在执行比较时忙于做其他事情,因此结果不可靠,并且应该再次运行基准。
For advanced PHP users, knowing the difference between
==
and===
and asking themselves "is it faster to compare with==
or with===
when I'm sure that both the operands are the same type?"The short and general answer is: There is no performance gain in using
===
in this cases, so you should probably use==
.For the ones interested in benchmarking it themselves, you can use the following code I wrote ad-hoc and try different values for
$a
and$b
:NOTE: The comparison is valid only when each "FIRST TRY" is very close to its "SECOND TRY". If they are significantly different, it means that the processor was busy doing something else while executing the comparisons and so the results are unreliable and the benchmark should be run again.