这个带有插入符号的 PHP 语法是什么?它有什么作用?
我在代码库中遇到了这种语法,但找不到更多有关它的信息。它看起来像插入符号运算符(XOR 运算符),但因为下面的语句是在满足某个条件时执行的,所以我认为不是这样。
$this->m_flags ^= $flag;
因为我不知道它叫什么,所以我也无法正确搜索它..
更新: 因为克莱图斯的回答: 那么下面的几行在功能上是相等的吗?
$a = $a ^ $b;
$a ^= $b; // the shorthand for the line above
I came across this syntax in a codebase and I can't find any more info on it. It looks like the caret operator (XOR operator), but because the statement below was executed when a certain condition was met I don't think that is it.
$this->m_flags ^= $flag;
Because I don't know what it's called I also can't search for it properly..
Update:
Because of Cletus' answer:
Are the following lines then functionally equal?
$a = $a ^ $b;
$a ^= $b; // the shorthand for the line above
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它是按位异或等于。它基本上会切换一个标志,因为我得到的
$flag
是 2 的幂。举个例子:所以第三位已经被翻转了。再次:
It's bitwise XOR equals. It basically toggles a flag because I'm getting
$flag
is a power-of-2. To give you an example:So the third bit has been flipped. Again:
按位异或和赋值运算符
http://php.net/manual/en/language.operators.bitwise.php
Bitwise XOR and assign operator
http://php.net/manual/en/language.operators.bitwise.php