home—lects—hws
D2L—zoom (snow day)
array practice
Review highlights:
-
what do we put at the top of EVERY file, so that error-messages get reported?
(What sort of errors does it help catch?)
-
PHP strings can use _____ OR _____.
What's the difference between them?
Which one does Barland recommend?
Why?
-
The PHP array-constructor is named ______.
Fun fact: starting in php 5.4, you
can just use [ and ] to make an array-constructor.
Unfun fact: RU's antiquated php version 5.2 doesn't allow this syntax. Grrr.
-
PHP arrays differ from (say) Java arrays, in that ...
-
Never loop through an array via ______. (Why not?)
checkpoint: we spent the whole class discussing this and
related thoughts, and it seemed to be worth it.
Okay, we watched the
video about
looping over arrays, in php,
and,
writing the function "ol".
So now we
have a php-arrays-practice-files/utils_php.txt
(and
php-arrays-practice-files/utils-test_php.txt)
with the code for
hyperlink and ol.
TASK:
write a function which takes in a bunch of URLs,
and returns an html-ordered-list of those as clickable links.
TASK, version 2:
as before, but the input will be key/value pairs of
Pro tip: array_map!
Using arrays and nested loops, to create html radio-buttons
coming up:
We'll visit this example after discussing html input tags.
Design exercise:
We want to set up a web-form, where people enter information about
PokemonOkaymon.
discussion answers:
If solutions are not already being displayed,
see php-arrays-practice-soln.html for a sketch of where the discussion might lead.
distance lecture version:
breeze video (1h42m);
and the
tests/code typed therein (roughly same as on this page).
-
For the monster's element (
fire, grass, watercandle, clover, puddle),
what input-type should we use?
-
The list of elements might change over time (adding new elements).
Should the drop-down be hand-coded?
-
Each monster has some elements that they are weak to.
How should we collect that?
-
And each monster also has some elements they are resistant to.
So that'd be another bank of checkboxes.
But wait: you can't be both resistant and weak to the same element.
So what should the form do, as we mark various weaknesses/resistances?
-
Is there a better way?
-
Will this scheme generalize to other purposes?
-
So we'll make this a php function, which takes in information and
produces a (big long) string of html, for this 'radio-table'.
A table-layout seems reasonable.
What should the signature be?
-
(We sketch out what we want the table to look like.)
-
We can make a unit-test:
-
We'll need this radiotable for the homework.
Can we write a bunch of the code right now?
video from distance lecture (breeze),
2017-feb-07 (1h42m): review forms, and work through radioTable
home—lects—hws
D2L—zoom (snow day)
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |
|