Today, a friend in the group asked a question about bitwise AND or ..
I have been working in PHP for a year. Maybe I am not familiar with this part. Here I will introduce this part to new users.
Operations on binary data are mainly performed by location.
<?PHP$= 1;$ B= 2;$ C=$^B;Echo $ C//3?>
This is not a simple addition.
Convert decimal 1 to binary 00000001
Convert decimal 2 to binary 00000010
Bitwise ^ 00000011 // The values of different values are regarded as 1 ^
Then,
<? PHP $ A = 1; $ B = 2; echo $ A & $ C; // 1?>
Convert decimal 3 to binary 00000011
Convert decimal 1 to binary 00000001
Bitwise & 00000001 // The value remains the same for each single digit. Otherwise, the value is 0.
Finally, we will introduce the usage; it makes no sense to return values after bitwise. It is mainly used to determine whether $ A exists in $ C. // There are many permission usage options.
<? PHP $ My_privilege = 15; // 1 + 2 + 4 + 8 with all Permissions $ PRI ='' ; $ Privilege_arr = Array (8 => 'add', 4 => 'delete', 2 => 'modify', 1 => 'check' ); Foreach ( $ Privilege_arr As $ K => $ V ){ $ K & $ My_privilege && $ PRI . = 'I '.$ V . 'Power <br>' ;} Echo $ PRI ; ?>