Reputation: 349
I have the following flags:
- edit profile => 1
- update coupon => 2
- update news articles => 4
I want to understand how can I set and check the bit mask for all the three flags (that is, the user has access to all 3 bit masks).
Not quite sure what to do here.
Upvotes: 2
Views: 38
Reputation: 5886
If you want a user to have all the permissions then or
the bits.
e.g.
$permission_bitmask = $edit_profile | $update_coupon | $update_news_articles;
For just two of the permissions, it's the same idea.
$permission_bitmask = $edit_profile | $update_coupon;
To check the bitmask, and the bitmask with your desired bit.
$has_edit_profile = ($edit_profile & $permission_bitmask) !== 0;
Upvotes: 2