Hi,

Wednesday, November 6, 2002, 2:56:33 PM, you wrote:
DV> Does anyone know of a nice efficient way to convert an array of values
DV> into a "mask"...

DV> Here's the deal. Given an array such that:

DV> $purchitem[0] = 1;
DV> $purchitem[1] = 3;
DV> $purchitem[2] = 4;

DV> I want to end up with a variable like this:

DV> $mask = "10110";

DV> Additionally, my theory is that then the person purchases another book
DV> later

DV> $purchitem[0] = 2;

DV> My new mask should be $purchmask = "01000";

DV> Then I can load their previous mask from the database and boolean OR it
DV> with the new mask to set the correct permissions. i.e.

DV> $newmask = $mask | $purchmask;

DV> Or ideally = "11110"

DV> Can I boolean OR strings like that in the way I 'hope' it will work? Do
DV> I need to convert it to an intermediate stage or cast it or anything?

DV> Does this make sense? It's for an online book shopping cart. I have the
DV> reverse working, where I can split the mask into what books. And I also
DV> have the $purchitem[] working.

This should do it:


$purchitem[0] = 1;
$purchitem[1] = 3;
$purchitem[2] = 4;

$s = '00000';
while(list($key,$val) = each($purchitem)){
        $s[$val-1] = '1';
}
echo "s = $s <br>";

-- 
regards,
Tom


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to