I have a character string representing the days of the week in a "binary" format. Example: 1001110.
In this example: Monday is TRUE, Tuesday, FALSE, Wednesday FALSE, Thursday TRUE, Friday TRUE, Saturday TRUE, Sunday FALSE
How to determine if the current day is true or false with the easiest and most elegant way possible.
I have already been able to convert the binary string into days of the week, then I can compare it with the current day, but I'm looking for a lighter method, (if it's possible ..)
<?php
$arr_jours = array();
$arr_jours = array(
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday'
);
$week = "1001110";
$search_arr = str_split($week);
$out = array();
foreach($search_arr as $key => $value) {
if ($value == 1) {
$out[] = $arr_jours[$key];
}
}
if (in_array(date('l') , $out)) {
echo "Current day is TRUE";
}
else {
echo "Current day is FALSE";
}
?>
This works but I try to make it more elegant. How can I best optimize this code?
Thanks for your help.