I first practiced a "foreach" loop. These three divs show the progression from static to dynamic. This is a static row of images.
High elevation fields support tundra-like vegetation
A well-utilized tree with interesting fungi
Really cool fungi
Snow curtains form after a few thermal cycles
This is a row of images and a second row of captions generated (with technique in your first video) with two separate foreach loops. They do not align properly at narrower screen widths.
Caption 1
Caption 2
Caption 3
Caption 4
Fortunately I found the associative array easy enough to implement, https://www.w3schools.com/php/php_arrays_associative.asp. For completeness in my own learning, I've printed my print_r().
Array ( [IMG_0523.jpg] => High elevation fields support tundra-like vegetation [IMG_1159.jpg] => A well-utilized tree with interesting fungi [IMG_1448.jpg] => Really cool fungi [IMG_2461.jpg] => Snow curtains form after a few thermal cycles )
High elevation fields support tundra-like vegetation
A well-utilized tree with interesting fungi
Really cool fungi
Snow curtains form after a few thermal cycles
1. A simple version of this can be done with switches as in your first video with times instead of months. Input the hour of the day on line 118. This is the output:
Good Evening!
2. For a more complex output, some basics to start. I've set the Eastern time zone, but this doesn't affect (every) output (, only displays?).
Current time can be printed using numerous functions. Proved frustrating that there was no "time of day" when using that function (it was still the total number of seconds since Unix Epoch).
To help me understand differences, echo or print a bunch of variables and functions, files referenced in source code:
Print the DateTime object (variable) $now:
DateTime Object
(
[date] => 2024-09-27 21:26:22.360540
[timezone_type] => 3
[timezone] => America/New_York
)
Echo the day from the DateTime object (variable) $now:
Friday
These are the calculations I need to do to display a greeting based on the time of (any) day:
Number of seconds in a day = 24 * 60 * 60 = 86,400
One hour = 3600 seconds
Need to subtract five hours because calculation is done off of UTC.
Five hours = 18,000 seconds
Six hour = 21,600 seconds, will be needed for 4 segments of day.
METHOD:
Set $now = the current date or time since they both seem to give the same answer in integer form.
Divide by 86,400 to get the number of days after UnixEpoch.
Define a variable that will be the whole number, discarding the numbers after the decimal using round down, floor.
Then subtract this whole number from the days after UnixEpoch to get just the numbers after the decimal.
Then use if statements to compare to time of day breakpoints.
First I print out the variables and with the adjustment on line 217 the last two are now Eastern time.
1727468782This is where all the logic is taking place.
0Output:
My Greeting: Good Evening!