That's the EASY part John!

The hard part is converting the array (which was a checkbox array from a
form submission) into the binary string (as per the original post)

> Here's the deal. Given an array such that:
> $purchitem[0] = 1;  //purchased book #1 checkbox enabled
> $purchitem[1] = 3;  //purchased book #3 checkbox enabled
> $purchitem[2] = 4;  //purchased book #4 checkbox enabled
> I want to end up with a variable like this:
> $mask = "10110";

Get it now? ;-)
 

> -----Original Message-----
> From: John W. Holmes [mailto:holmes072000@;charter.net] 
> Sent: Wednesday, November 06, 2002 4:19 AM
> To: 'Jon Haworth'; [EMAIL PROTECTED]
> Subject: RE: [PHP] How do I convert an array into a mask?
> 
> 
> > Hi John,
> > 
> > > > So given the example below, "10110"
> > > > means that the person can view books 1, 3, and 4,
> > > > but not 2 or 5. dig?
> > >
> > > Explain that to me... I know binary, but I can't see
> > > how that equates to 1, 3, and 4.
> > 
> > Because you know binary :-)
> > 
> > The above is a series of yes/no flags, not a binary number. Reading
> from
> > left to right:
> > 
> > book 1 : yes
> > book 2 : no
> > book 3 : yes
> > book 4 : yes
> > book 5 : no
> > 
> > Cheers
> > Jon
> 
> Ok, so knowing binary and now knowing that, :)
> 
> Couldn't you just treat the number as a string and tear it 
> apart to see what permissions the user has?
> 
> <?
> 
> $var = "10110";
> 
> $l = strlen($var);
> 
> for($x=0;$x<$l;$x++)
> {
>   if($var{$x}) 
>   { echo "Permission for book $x is good<br>\n"; }
>   else
>   { echo "Permission for book $x is bad<br>\n"; }
> }
> 
> ?>


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

Reply via email to