PHP Array Demo
An array is kind of like a temporary spreadsheet to hold data for a program to use. It's a data structure.
The simplest array is a two dimensional matrix of fields and values.
If the field is named 'state' then a possible value could be 'Kansas'.
In this first example, we initialize an array about Texas with the following assignment:
texas = array('state' => 'texas','flower' => 'bluebonnet','capitol' => 'Austin'
Then we output the value of the capitol field with a PHP echo $texas['capitol'].
The capitol of texas is austin
Next we set up an array with several states using an assignment like:
$usa = array ("states" => array("texas", "new york", "california"),
"birds" => array("mockingbird", "bluebird", ....
and output the California state bird using an index rather than field name: $usa['birds'][2]
The state bird of cali is california valley quail
That's pretty easy but not so useful since we hardcode the index of the value that we want.
Finally, we demonstrate how this might be used in an application. We'll pass a variable (state name) and search and find the state bird.
We'll use a variable rather than a hardcoded index (row of the array): $usa['birds'][$key]