I try the following:
Compare today's date in the array.
Count how many are on or off.
And list them.
And find out which ones are online or offline.
$dateArray = [];
$dateArray = [
'hercules' => ['date' => ['start' => '2019-10-13','end' => '2021-01-01']], // on
'serto' => ['date' => ['start' => '2019-12-11','end' => '2019-12-20']], // off
'alex' => ['date' => ['start' => '2019-08-20','end' => '2023-01-05']], // on
'herbert' => ['date' => ['start' => '2020-11-11','end' => '2021-09-17']], // off
'wolfy' => ['date' => ['start' => '2019-09-04','end' => '2021-01-01']], // on
'susi' => ['date' => ['start' => '2021-05-10','end' => '2022-01-01']] // off
];
$currentDate = date("Y-m-d");
// check date for on
foreach($dateArray as $date){
if ($date['date']['start'] <= $actualDate && (empty($date['date']['end']) || $date['date']['end'] >= $actualDate )){
$on = $date;
$countOn = count($on);
}
}
echo 'on ('.$countOn.') is: ';
foreach ($on as $pers){
echo $pers.', ';
};
echo '<br>';
// check date for off
foreach($dateArray as $date){
if ($date['date']['start'] <= $actualDate && (empty($date['date']['end']) || $date['date']['end'] <= $actualDate )){
$off = $date;
$countOff = count($off);
}
}
echo 'off ('.$countOff.') is: ';
foreach ($off as $pers){
echo $pers.', ';
};
echo '<br>';
// message
echo 'hello, '.$pers['herbert'].' is '.$onORoff.' and '.$pers['alex'].' is '.$onORoff.'!';
expected
on (3) is: hercules, alex, wolfy
off (3) is: serto, herbert, susi
hello, herbert is off and alex is on!