Example converting binary value to array of string values.
$definition = array( 1=> 'category 0',
2=>'category 1',
4=>'category 2',
8=>'category 3',
16=>'category 4',
32=>'category 5',
64=>'category 6',
128=>'category 7',
256=>'category 8',
512=>'category 9'
);// on to the limit of a 32-bit integer
$category_array[ ] = "";
$category = (int) 3;
$binarycategory = sprintf("%08s",DecBin($category));
print("Category value in the database:$category ($binarycategory) <br>");
for($shifter=1;$shifter<=512;$shifter=$shifter<<1) {
$binaryshifter = sprintf("%08s",DecBin($shifter));
print("tested against shifter bit value:$shifter ($binaryshifter) --> ");
($category & $shifter)?print("This is a $definition[$shifter]<br>"):print("This is NOT a $definition[$shifter]<br>");
}
OUTPUT:
Category value in the database:3 (00000011)
tested against shifter bit value:1 (00000001) --> This is a category 0
tested against shifter bit value:2 (00000010) --> This is a category 1
tested against shifter bit value:4 (00000100) --> This is NOT a category 2
tested against shifter bit value:8 (00001000) --> This is NOT a category 3
tested against shifter bit value:16 (00010000) --> This is NOT a category 4
tested against shifter bit value:32 (00100000) --> This is NOT a category 5
tested against shifter bit value:64 (01000000) --> This is NOT a category 6
tested against shifter bit value:128 (10000000) --> This is NOT a category 7
tested against shifter bit value:256 (100000000) --> This is NOT a category 8
tested against shifter bit value:512 (1000000000) --> This is NOT a category 9