Bitwise AND
s:
$input = 13;
if( $input & 1 ) {
echo 'Monday';
}
if( $input & 2 ) {
echo 'Tuesday';
}
if( $input & 4 ) {
echo 'Wednesday';
}
// etc
edit
You can avoid the if
s with something like:
$input = 13;
$days = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');
for( $i=0; $i<7; $i++ ) {
$daybit = pow(2,$i);
if( $input & $daybit ) {
echo $days[$i] . ' ';
}
}
//output: mon wed thu
There's more than these two ways to skin this particular cat, but the 'best' way depends on what your result/output needs to be.