I found the example arrays in W3Schools easy to understand, except those with symbols or operands we haven't yet reviewed. I only have four examples because I found myself trying to solve some that were too hard but I did quite a bit of manipulation to the "try it" examples. I have not figured out how to work with an associative array that has more than one key : value pair as noted in the last example.

Sadly, my file is a validation nightmare and I don't have enough time to fix all the problems. I will do so after the fact.

The images are one level up on the server.

ARRAY & LOOP #1: I'm repeating my image array from last week because the focus was more on dates and times and I thought it may have gotten lost in the shuffle.

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



ARRAY & LOOP #2: I set up a loop structure for the books that will go into this page, https://dam00238.classweb.vsc.edu/books.php. I tried to do it as an associative array as in the first commented out array but had to use indexed arrays instead. I will eventually pull the information from a MySql database, but started here with the skeleton.

link1.php
Treating Pathological Narcissism...
diamond_book_sm.jpg
Filling a crucial gap...
link2.php
Transference-Focused Psychotherapy...
TFPAdolescentssm.jpg
Offering clinicians a comprehensive...
link3.php
Psychodynamic Therapy for...
book2018sm.jpg
Deftly combining contemporary...


ARRAY & LOOP #3: For this example, I used one of my plant lists from this week's regular Web Dev course, set it up as a multi-dimensional indexed array, and displayed it with a foreach loop using table structure. This method seems like it would be good for working off of a comma-separated CSV file (if the info wasn't already in a database) while making sure to escape any references to inches.

The foreach loop seems more straightforward than the "for" example https://www.w3schools.com/php/php_arrays_multidimensional.asp and https://www.w3schools.com/php/phptryit.asp?filename=tryphp_array_multi2

Garden Bed Planning

Type GENUS VARIETY / CULTIVAR DESCRIPTION HT
VegetableTomatoJuliet60 days; indeterminate; 1oz oval; disease resistant
VegetableTomatoRed Grape60 days; indeterminate clusters of grape sized fruit
VegetableTomatoSun Gold57 days; tangerine cherry; 1" fruit; indeterminate
VegetableZucchiniRomanesco52 days; flavorful, ribbed Italian zucchini
VegetableZucchiniSpace Miser54 days; high yielding zucchini on compact plants
HerbBasilGenoveselarge, aromatic green leaf
HerbBasilSweet Basilcommon basil20-30"
HerbOreganoGreekpungent spreading herb
HerbRosemaryGorizialarge, flat leaves; rigidly upright
HerbSageBerggartengrey green leaf10-12"
HerbThymeEnglishfragrant, green leaves12"
AnnualCalendulaBon Bon Orangeearly, brilliant orange15"
AnnualMarigoldDisco Mixmix of single petaled flowers on dwarf plants12"
AnnualNasturtiumEmpress of Indiavermillion flowers; blue green foliage; edible10"


IDEA (#5): make a chart of >5 running results, display the top five (by limiting a loop) in winning order with differential times. Use a "while" for the known fastest (manually) in order to calculate differentials.

This is the example that stumped me. I realize the idea is rather complex. Although asort is to be used on an associative array, I could not find instructions or learn by trial and error how to sort (a multi-dimensional array) based on the third key. I'll come back to this later in the course. What I was able to complete:

ARRAY & LOOP #4: I set up the runners in a multi-dimensional associative array, and displayed it sorted by first name with a foreach loop using table structure.

The associative part is moot unless I can use different keys or perhaps use the key to dynamically create the table headers. Below the table, I repeat some of the code to show that I was able to display the outer and inner loops and keys.

10K Results

FIRST NAME LAST NAME ELAPSED TIME DIFFERENTIAL TIME
ArthurCurry38:29 
BarryAllen52:39 
BruceWayne34:59 
ClarkKent50:49 
DianaPrince47:39 
VictorStone46:19 


Array ( [0] => Array ( [firstname] => Diana [lastname] => Prince [elapsedTime] => 47:39 ) [1] => Array ( [firstname] => Clark [lastname] => Kent [elapsedTime] => 50:49 ) [2] => Array ( [firstname] => Bruce [lastname] => Wayne [elapsedTime] => 34:59 ) [3] => Array ( [firstname] => Victor [lastname] => Stone [elapsedTime] => 46:19 ) [4] => Array ( [firstname] => Arthur [lastname] => Curry [elapsedTime] => 38:29 ) [5] => Array ( [firstname] => Barry [lastname] => Allen [elapsedTime] => 52:39 ) )

Array ( [firstname] => Arthur [lastname] => Curry [elapsedTime] => 38:29 ) outer loop
firstname: Arthur inner loop
lastname: Curry inner loop
elapsedTime: 38:29 inner loop
Key=elapsedTime, Value=38:29, simply repeats the final key : value pair, inner loop

Array ( [firstname] => Barry [lastname] => Allen [elapsedTime] => 52:39 ) outer loop
firstname: Barry inner loop
lastname: Allen inner loop
elapsedTime: 52:39 inner loop
Key=elapsedTime, Value=52:39, simply repeats the final key : value pair, inner loop

Array ( [firstname] => Bruce [lastname] => Wayne [elapsedTime] => 34:59 ) outer loop
firstname: Bruce inner loop
lastname: Wayne inner loop
elapsedTime: 34:59 inner loop
Key=elapsedTime, Value=34:59, simply repeats the final key : value pair, inner loop

Array ( [firstname] => Clark [lastname] => Kent [elapsedTime] => 50:49 ) outer loop
firstname: Clark inner loop
lastname: Kent inner loop
elapsedTime: 50:49 inner loop
Key=elapsedTime, Value=50:49, simply repeats the final key : value pair, inner loop

Array ( [firstname] => Diana [lastname] => Prince [elapsedTime] => 47:39 ) outer loop
firstname: Diana inner loop
lastname: Prince inner loop
elapsedTime: 47:39 inner loop
Key=elapsedTime, Value=47:39, simply repeats the final key : value pair, inner loop

Array ( [firstname] => Victor [lastname] => Stone [elapsedTime] => 46:19 ) outer loop
firstname: Victor inner loop
lastname: Stone inner loop
elapsedTime: 46:19 inner loop
Key=elapsedTime, Value=46:19, simply repeats the final key : value pair, inner loop


©2022 Darlene McCormick • Web page by me