我遇到了一些我在继承的系统中不常见的PHP代码。PHP&and |运算符
为了简化计算,代码如下:
$test_array['first_element'] = 1 | 2;
$test_array['second_element'] = 3 & 1;
,并继续像这样几行。
我似乎找不到对应于这种类型的操作符的PHP手册中的任何东西。我很感激即使是链接到文章或解释此代码结果的一些文档。
我遇到了一些我在继承的系统中不常见的PHP代码。PHP&and |运算符
为了简化计算,代码如下:
$test_array['first_element'] = 1 | 2;
$test_array['second_element'] = 3 & 1;
,并继续像这样几行。
我似乎找不到对应于这种类型的操作符的PHP手册中的任何东西。我很感激即使是链接到文章或解释此代码结果的一些文档。
& (Bitwise AND)
Performs the AND operation on each pair of bits. a AND b yields 1 only if both a and b are 1
e.g:
0101 (decimal 5)
AND 0011 (decimal 3)
= 0001 (decimal 1)
| (Bitwise OR)
Performs the OR operation on each pair of bits. a OR b yields 1 if either a or b is 1
e.g:
0101 (decimal 5)
OR 0011 (decimal 3)
= 0111 (decimal 7)
您正在寻找PHP的Bitwise Operators。
这是数字按位比较 - 但它似乎没有意义比较静态数字。
这里有很多的背景看:http://php.net/manual/en/language.operators.bitwise.php
如果您访问“操作员”页面,你会发现[运算符优先级]表(http://www.php.net/manual/ EN/language.operators.precedence.php)。其余的很容易。 – Jon