Different uses of the PHP median operation (bitwise and, bit, or)

Source: Internet
Author: User
What is the role of bitwise-and-bitwise, or in the development process of PHP?
    1. /**
    2. * 1. Permission application
    3. * What permissions you have, add up the values corresponding to these permissions
    4. * For example: Moderator has permission (add, delete, modify, query), the moderator's permission value is stored as 15 (8+4+2+1)
    5. * then "sum of permission values" is compared to "actual permission value"
    6. * The result is true and has permissions
    7. * result is false then no permission
    8. *
    9. * Note: The permission value must be 2 of the N-square, starting from 0 times, 31 times is 2147483648
    10. * 32 times is 4294967296, has exceeded the usual int (10) maximum storage 4294967295, so must pay attention to the number of permissions (<31)
    11. * Of course, if the storage format is bitint or varchar, etc. can store longer numbers, then the number of permissions can continue to increase
    12. */
    13. $permission = 15; 1+2+4+8 has full privileges
    14. $permissions = Array (
    15. 8 = ' Increase ',
    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. ' The Power
      ';
    23. }
    24. }
Copy Code
    1. Waiting to be added
Copy Code
  • 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.