RE: [PHP] How do I convert an array into a mask?
| From: | John W. Holmes | Date: | Wed, 06 Nov 2002 12:18:47 +0000 |
| Subject: | RE: [PHP] How do I convert an array into a mask? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-122968@lists.php.net to get a copy of this message | ||
> 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"; }
}
?>
---John Holmes...