How do I convert an array into a mask?
| From: | Daevid Vincent | Date: | Wed, 06 Nov 2002 04:56:33 +0000 |
| Subject: | How do I convert an array into a mask? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-122935@lists.php.net to get a copy of this message | ||
Does anyone know of a nice efficient way to convert an array of values
into a "mask"...
Here's the deal. Given an array such that:
$purchitem[0] = 1;
$purchitem[1] = 3;
$purchitem[2] = 4;
I want to end up with a variable like this:
$mask = "10110";
Additionally, my theory is that then the person purchases another book
later
$purchitem[0] = 2;
My new mask should be $purchmask = "01000";
Then I can load their previous mask from the database and boolean OR it
with the new mask to set the correct permissions. i.e.
$newmask = $mask | $purchmask;
Or ideally = "11110"
Can I boolean OR strings like that in the way I 'hope' it will work? Do
I need to convert it to an intermediate stage or cast it or anything?
Does this make sense? It's for an online book shopping cart. I have the
reverse working, where I can split the mask into what books. And I also
have the $purchitem[] working.