“true == isset($variable)”和“true == isset($variable)”之间的区别和“isset($variable) == true”在 PHP 中
我只是在思考 PHP 中条件相等的概念,即
之间有什么区别
true == isset($variable)
和
isset($variable) == true
?
I was just wandering the about the concept of equating the condition in PHP that is,
what could be the difference between
true == isset($variable)
and
isset($variable) == true
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对于这个具体情况,没有区别。
第一种语法用于防止意外赋值而不是比较。
但同样,就你的情况而言,没有区别。
详细说明:
假设您想要将变量
$x
与true
进行比较并执行某些操作。你可能会不小心写成“of”
,并且条件总是会通过。
但如果你养成了编写的习惯,
这些错误就不会发生,因为会生成语法错误,而你会提前知道。
For this specific case, no difference.
The first syntax is used to prevent accidental assignment instead of comparison.
But again, in your case, no difference.
Elaboration:
Say you want to compare a variable
$x
totrue
and do something. You could accidentally writeinstead of
and the condition would always pass.
But if you get into the habit of writing
these mistakes wouldn't happen, since a syntax error would be generated and you would know in advance.
没有什么区别。但isset()本身返回一个布尔值。
所以永远不要使用
只是:
There is no difference. But
isset()
itself returns a boolean value.So never use
Just:
请记住,当 php 解析时,true 已实际定义,并且它等于 1。此外,false 也是如此,它等于 0。php 会自动检查这些值,以便与 IF 语句中的这些值进行比较。您将安全使用!运算符,因为它与 if ($something == false) 相同,祝你好运!
Remember that when php parses that true is actually defined and its equal to 1. Furthermore so is false and it is equal to 0. php automatically checks these for comparison with these values in an IF statement. You'll be safe using the ! operator, because its the same as if ($something == false) good luck!
如果是Java,那就有区别了。
IE
Would it be Java, there was difference.
i.e.
不存在“真正的”差异(在本例中)
之间
true == isset($variable)
AND
There is no "real" diffrences(in this case)
Between
true == isset($variable)
AND