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
A well-utilized tree with interesting fungi
Really cool fungi
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.phpARRAY & 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
Type | GENUS | VARIETY / CULTIVAR | DESCRIPTION | HT |
---|---|---|---|---|
Vegetable | Tomato | Juliet | 60 days; indeterminate; 1oz oval; disease resistant | |
Vegetable | Tomato | Red Grape | 60 days; indeterminate clusters of grape sized fruit | |
Vegetable | Tomato | Sun Gold | 57 days; tangerine cherry; 1" fruit; indeterminate | |
Vegetable | Zucchini | Romanesco | 52 days; flavorful, ribbed Italian zucchini | |
Vegetable | Zucchini | Space Miser | 54 days; high yielding zucchini on compact plants | |
Herb | Basil | Genovese | large, aromatic green leaf | |
Herb | Basil | Sweet Basil | common basil | 20-30" |
Herb | Oregano | Greek | pungent spreading herb | |
Herb | Rosemary | Gorizia | large, flat leaves; rigidly upright | |
Herb | Sage | Berggarten | grey green leaf | 10-12" |
Herb | Thyme | English | fragrant, green leaves | 12" |
Annual | Calendula | Bon Bon Orange | early, brilliant orange | 15" |
Annual | Marigold | Disco Mix | mix of single petaled flowers on dwarf plants | 12" |
Annual | Nasturtium | Empress of India | vermillion flowers; blue green foliage; edible | 10" |
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.
FIRST NAME | LAST NAME | ELAPSED TIME | DIFFERENTIAL TIME |
---|---|---|---|
Arthur | Curry | 38:29 | |
Barry | Allen | 52:39 | |
Bruce | Wayne | 34:59 | |
Clark | Kent | 50:49 | |
Diana | Prince | 47:39 | |
Victor | Stone | 46:19 |
©2022 Darlene McCormick • Web page by me