Bitwise AND is mainly an operation on binary numbers.
The code is as follows:
Copy code The code is as follows:
$a = 1;
$b = 2;
$c = $a^b;
echo $c // 3
?>
This is not simple Addition relationship
Decimal 1 is converted to binary 00000001
Decimal 2 is converted to binary 00000010
Bitwise^ 00000011 // Even if they are not the same, they are all counted as 1^_^
Then,
Copy code The code is as follows:
$a = 1;
$b = 2;
echo $a & $c; // 1
?>
Decimal 3 converted to binary 00000011
Decimal 1 converted to binary 00000001
Bitwise & 00000001 / / means that all digits are the same, otherwise they are counted as 0
Finally, let’s introduce the usage; it is meaningless to return the value after bitwise &. Mainly used to determine whether $a exists in $c // There are many permission usages.
Copy code The code is as follows:
$my_privilege = 15; // 1+2+ 4+8 has all permissions
$Pri = '';
$privilege_arr = array(8=>'Add', 4=>'Delete',2=>'Change',1=> ;'Check');
foreach($privilege_arr as $k =>$v){
$k & $my_privilege && $Pri .= 'I have the power of'.$v.'
}
echo $Pri;
?>
http://www.bkjia.com/PHPjc/728104.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/728104.htmlTechArticleBitwise AND is mainly an operation on binary numbers. The code is as follows: Copy the code as follows: ?php $a = 1; $b = 2; $c = $a^b; echo $c // 3 ? This is not a simple addition relationship. Decimal 1 is converted into...