Class Exercise: Arrays
Array: A collection of a fixed number of components all of the same data type.
When one-dimensional, the components are arranged in list form.
General Form:
$arrayName = array();
For example: $color = array("red","green");
Index: A non-negative integer that specifies the position of a component in
an array. For example:
$color[2] = "blue";
assigns "blue" to component 2 (i.e. relative to 0, so the 3rd list item).
1. Use the array() function to declare $groceryList before referencing it
(i.e. no actual parameter values).
2. Declare an array named $groceryList with argument values so components are
assigned the values: "lettuce","tomato","potato","banana","bread","coffee".
3. Utilize the count() function with the array name as its argument to
determine the number of elements in $groceryList.
4. Prepare a program fragment to input and store a new list of grocery items
input from the file "list.txt" and stored as elements of $groceryList.
Note: with fgets(), "new lines" will be appended to each item.
5. Write a program fragment containing a conventional for loop to search
$groceryList for an array element containing the value "coffee", then assign
the index value of that element to $ndx.
6. Code an assignment statement to replace "coffee" with "tea" in $groceryList.
7. Code a foreach loop to print the values stored in $groceryList.
8. Apply the sort() function to order the $groceryList elements. Array name is
passed as a parameter to this function. Output the ordered list.