<?php
/**
* Keys are ISO-8601 numeric representation
* of the days of the week
*/
$days = [
1 => 0b0000001, // 1
2 => 0b0000010, // 2
3 => 0b0000100, // 4
4 => 0b0001000, // 8
5 => 0b0010000, // 16
6 => 0b0100000, // 32
7 => 0b1000000, // 64
];
$mondayToFriday = 31; // 1 + 2 + 4 + 8 + 16
foreach ($days as $n => $v) {
/**
* Get the day's name using strftime (has locale capability)
* strtotime("Sunday +n days") would work with ISO-8601 day
* numbers or PHP's date("w") (0 - 6 / Sunday - Saturday)
*/
$day = strftime("%A", strtotime("Sunday +{$n} days"));
echo "{$day}: " . (($v & $mondayToFriday) ? "Y" : "N") . PHP_EOL;
}
echo PHP_EOL;
/**
* The order of these is important
*/
$input["days"] = [
"Monday" => 0,
"Tuesday" => 1,
"Wednesday" => 0,
"Thursday" => 0,
"Friday" => 0,
"Saturday" => 0,
"Sunday" => 0,
];
$dec = bindec(strrev(implode("", $input["days"])));
echo "\$dec: {$dec}" . PHP_EOL;
preferences:
21.59 ms | 402 KiB | 5 Q