RE: [PHP] How do I convert an array into a mask?

From: Date: Wed, 06 Nov 2002 12:33:58 +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-122971@lists.php.net to get a copy of this message
> 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? ;-) Got it... Are there always going to be X digits in the code? If so, this would work. <? $purchitem[0] = 1; $purchitem[1] = 3; $purchitem[2] = 4; $mask = ''; $length = 5; $y = 0; for($x=1;$x<$length+1;$x++) { if(@$purchitem[$y] == $x) { $mask .= '1'; $y++; } else { $mask .= '0'; } } echo $mask; ?> ---John Holmes...

« previous php.general (#122971) next »