php中不比较时有两个等号
两个等号不用于比较时意味着什么?
$saveOrder = $listOrder == 'a.ordering';
我从来没有在 php 中见过这样的东西......我正在查看网页链接 Joomla 1.7 管理组件。
谢谢
What do the two equal signs mean when not being used to compare?
$saveOrder = $listOrder == 'a.ordering';
I've never seen anything like this in php.... I am looking at the weblinks Joomla 1.7 admin component.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
他们正在比较。它只是没有用括号括起来(就像使用
if
/while
/etc 的比较表达式)。$saveOrder
将被分配true
或false
(条件的结果)。They are comparing. It's just not wrapped in parenthesis (like a comparison expression with
if
/while
/etc).$saveOrder
will be assigned eithertrue
orfalse
(the result of the condition).我猜它与 $saveOrder = ($listOrder == 'a.ordering'); 相同
I guess it is the same as
$saveOrder = ($listOrder == 'a.ordering');
在您的声明中,双等号(==)仅用于比较目的。实际上,您的语句包含“赋值”(=) 和“比较”(==) 运算符,这会导致您感到困惑。
这相当于
$saveOrder = ($listOrder == 'a.ordering');
,因此首先将 $listOrder 与 'a.ordering' 进行比较,并将结果(true 或 false)分配给 $保存订单。希望这能消除您的困惑,如果不让我知道一次。
In your statement also the double equal sign(==) used for the comparison purpose only. Actually your statement contains both the 'assignment'(=) and 'comparison'(==) operators which leads to your confusion.
That is equivalent to
$saveOrder = ($listOrder == 'a.ordering');
, so first compares the $listOrder with 'a.ordering' and assign the result(true or false) to $saveOrder.Hope this clear you confusion, if not let me know once.
您可以看到打印第一个时的输出为
1
而第二个将返回:(即什么都没有)
You can see the output when printing the first will be
1
whereas the second will return:(i.e. nothing)
它用于用于比较。除了比较结果被分配给
$saveOrder
。以下代码:
将
true
分配给$saveOrder1
变量,并将false
分配给$saveOrder2
变量。如果您不相信,请在这里亲自检查。It is used for comparing. Except the result of the comparison is assigned to
$saveOrder
.The following code:
assigns
true
to the$saveOrder1
variable andfalse
to the$saveOrder2
variable. If you do not believe, check for yourself here.