Dar's PHP Page


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 vegetation

High elevation fields support tundra-like vegetation

A well-utilized tree with interesting fungi

A well-utilized tree with interesting fungi

Really cool mushrooms

Really cool fungi

Snow curtains form after a few thermal cycles

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

High elevation fields support tundra-like vegetation

A well-utilized tree with interesting fungi

A well-utilized tree with interesting fungi

Really cool fungi

Really cool fungi

Snow curtains form after a few thermal cycles

Snow curtains form after a few thermal cycles


Display a greeting based on time of day

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:

1727486448
2024-09-27 09:20:48pm

Array ( [sec] => 1727486448 [usec] => 940988 [minuteswest] => 240 [dsttime] => 1 )
1727486448.941
1727486448.941004

Array ( [seconds] => 48 [minutes] => 20 [hours] => 21 [mday] => 27 [wday] => 5 [mon] => 9 [year] => 2024 [yday] => 270 [weekday] => Friday [month] => September [0] => 1727486448 )
Friday, September 27, 2024 21:20:48
21

1727486448
1727486448
Friday 27th of September 2024 09:20:48 pm
09:20:48 PM

Print the DateTime object (variable) $now:
DateTime Object ( [date] => 2024-09-27 21:20:48.941069 [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.

1727468448
19993.847777778
19993
1727395200
73248
73248

This is where all the logic is taking place.

0
21600
43200
64800
86400
1727468448
Current time 09:20:48pm
2024

Output:

Hallelujah, I finally made it work!

My Greeting: Good Evening!