I am a pharmacist that maintains a small pharmacy organization web site. I have been using if elseif and else conditional statements to display the next meeting date based on today's date. This is becoming very cumbersome secondary to many date changes. I am trying to use an array to simplify this process.
I am trying to loop through the array and if the condition of today's date is before the next meeting then assign that date to a variable to display on the webpage. Here is what I have, but is not working. In the below example, we do not have any meeting in June, July or December, but could be added at a later date, so trying to keep them as a placeholder.
Thank you in advance for any help.
You don't know what you don't know...
I am trying to loop through the array and if the condition of today's date is before the next meeting then assign that date to a variable to display on the webpage. Here is what I have, but is not working. In the below example, we do not have any meeting in June, July or December, but could be added at a later date, so trying to keep them as a placeholder.
PHP:
<?php
//date variable
date_default_timezone_set("America/Chicago");
$date = date("Ymd"); //Date format as YYYYMMDD
//create array
$meetdate = array();
$meetdate[0] = "20190110"; //January
$meetdate[1] = "20190212"; //February
$meetdate[2] = "20190320"; //March
$meetdate[3] = "20180410"; //April
$meetdate[4] = "20180525"; //May
$meetdate[5] = ""; //June
$meetdate[6] = ""; //July
$meetdate[7] = "20180830"; //August
$meetdate[8] = "20180922"; //September
$meetdate[9] = "20181019"; //October
$meetdate[10] = "20181103"; //November
$meetdate[11] = ""; //December
sort($meetdate);
//find next meeting date
for ($index = 0; $index < count($meetdate); $index++){
if ($date <= $meetdate[$index] {
$nextmeetdate = $meetdate[$index]
} else {
$nextmeetdate = "Date to be announced";
}
}
echo $nextmeetdate;
?>
Thank you in advance for any help.
You don't know what you don't know...