PHP median (bitwise AND, bitwise OR)
What is the role of bitwise AND, bitwise, or in php development?
- /**
- * 1. permission application
- * If you have any permissions, add the values corresponding to these permissions.
- * For example, if the moderator has the permission (add, delete, modify, and query), the permission value of the moderator is stored as 15 (8 + 4 + 2 + 1)
- * Then compare the sum of the [permission value] with the [actual permission value] with the [location]
- * If the result is true, you have the permission.
- * If the result is false, you do not have the permission.
- *
- * Note: The permission value must be 2 to the npower, starting from 0 to the power, and 31 to 2147483648.
- * The Power of 32 is 4294967296, which has exceeded the maximum storage capacity of commonly used int (10) by 4294967295. therefore, pay attention to the number of permissions (<31)
- * Of course, if the storage format is bitint or varchar and other formats that can store longer numbers, the number of permissions can be increased.
- */
- $ Permission = 15; // 1 + 2 + 4 + 8 have all permissions
- $ Permissions = array (
- 8 => 'Add ',
- 4 => 'Delete ',
- 2 => 'modify ',
- 1 => 'query'
- );
- Foreach ($ permissions as $ key => $ val ){
- If ($ key & $ permission ){
- Echo 'I have'. $ val. 'power
';
- }
- }
- Pending
|