You need a bitwise-and:
if( $docs2view & 1 ) {...}
if( $docs2view & 2 ) {...}
if( $docs2view & 4 ) {...}
if( $docs2view & 8 ) {...}
if( $docs2view & 16 ) {...}
Here, I'm testing individual bits. If the bit is set, the condition will be non-zero (hence will evaluate to 'true').
You could possibly avoid a lot of code repetition by putting this in a loop and using the bit-shift operators (>>
and <<
).
You said:
Thank you, paddy! But I only need the lowest value that evaluates true. How do I tell the loop to stop as soon as it finds that?
You can either convert those statements to elseif
so that only the first becomes true, or you can do this (assuming you only check the first 8 bits):
$nextdoc = 0;
for( $i = 0; $i < 8; $i++ ) {
if( $docs2view & (1<<$i) ) {
$nextdoc = $i + 1;
break;
}
}