I am trying to use a multidimensional array for the first time, but having trouble getting the conditional search for "//Find next meeting date" section.
Any help would be appreciated. Thank you.
You don't know what you don't know...
Any help would be appreciated. Thank you.
PHP:
//today's date variable
date_default_timezone_set("America/Chicago");
$todaysdate = date("Ymd"); //Date format as YYYYMMDD
//create multidimentional array
$meetinfo = Array
(
array('meetdate' => "20190110", 'speaker' => "Bob", 'room' => "Classroom #1", 'ce' => 1.0),
array('meetdate' => "20180512", 'speaker' => "Joe", 'room' => "Classroom #3", 'ce' => 1.0),
array('meetdate' => "20180820", 'speaker' => "Sally", 'room' => "Classroom #6", 'ce' => 1.0),
);
// Sort the multidimensional array
usort($meetinfo, "custom_sort");
// Define the custom sort function
function custom_sort($a,$b) {
return $a['meetdate']>$b['meetdate'];
}
//find next meeting date
for ($index = 0; $index < count($meetinfo); $index++){
if ($todaysdate <= $meetinfo["meetdate"][$index]) {
$nextmeetdate = $meetdate["meetdate"][$index];
$nextmeetdate = date("l F d, Y", strtotime($nextmeetdate)); //format date
$speaker = $meetdate["speaker"];
$room = $meetdate["room"];
$ce = $meetdate["ce"];
break; //exit loop
} else {
$nextmeetdate = "TBA";
$speaker = "TBA";
$room = "TBA";
$ce = "TBA";
}
}
//show data
echo "<p><strong>" .$nextmeetdate. "</strong>"; echo "<br />";
echo "Speaker: " .$speaker. ""; echo "<br>";
echo "Topic: " .$topic. ""; echo "<br />";
echo "Location: " .$location. "";echo "<br />";
echo "CPE CE: " .$ce. "contact hour"; echo "<br />";
echo "</p>";
You don't know what you don't know...