PHP median (bitwise AND, bitwise OR)

Source: Internet
Author: User
PHP median (bitwise AND, bitwise OR)
What is the role of bitwise AND, bitwise, or in php development?

  1. /**
  2. * 1. permission application
  3. * If you have any permissions, add the values corresponding to these permissions.
  4. * 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)
  5. * Then compare the sum of the [permission value] with the [actual permission value] with the [location]
  6. * If the result is true, you have the permission.
  7. * If the result is false, you do not have the permission.
  8. *
  9. * Note: The permission value must be 2 to the npower, starting from 0 to the power, and 31 to 2147483648.
  10. * 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)
  11. * 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.
  12. */
  13. $ Permission = 15; // 1 + 2 + 4 + 8 have all permissions
  14. $ Permissions = array (
  15. 8 => 'Add ',
  16. 4 => 'Delete ',
  17. 2 => 'modify ',
  18. 1 => 'query'
  19. );
  20. Foreach ($ permissions as $ key => $ val ){
  21. If ($ key & $ permission ){
  22. Echo 'I have'. $ val. 'power
    ';
  23. }
  24. }

  1. Pending

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.