HW12 - PHP

This assignment will illustrate use of associative arrays in PHP, together with the sort functions and the foreach statement. You are to create a php file named hw12.php which prints a list of all of the values passed in by the GET method, one line per name and value pair. The $_GET variable is actually an associative array. I want you to print the list 3 times, with a heading above each list and a count of the number of items printed below each list as follows:

1. The first heading should say “Data Received (unsorted)” which is followed by each of the name and value pairs (displayed as = , each on its own line). Beneath the list display “There are N values”, where N is the number of lines printed above (possibly 0).

2. The second heading should say “Data Received (sorted by name)” followed by each of the name = value pairs sorted by key names. The function you need to use for this is the ksort() function. If there are no set values in $_GET, then write NONE (don’t print the total number of items since you did that already above).

3. The third heading should say “Data Received (sorted by value)” followed by each of the name = value pairs sorted by value. The function you need to use for this is the assort() function. If there are no set values in $_GET, then write NONE (don’t print the total number of items since you did that already above).

To test to see that your hw12.php works, create a file called hw12.html that has a series of headings (Test 1, Test 2, … etc), a brief paragraph underneath to say what is being passed, and a link that includes the data in the URL (I am not asking you to create an html FORM for this assignment). For example, the following link will pass 6 different name and value pairs to hw12.php when someone clicks “Test 2”:

Test 2

The hw12.html file should have at least 6 different tests as follows:

1. Test 1 should have NO data passed, that is href="hw12.php" in the -tag

2. Test 2 should identical to the Test 2 example above. Is the unsorted listing in the same order as listed in the URL? If not, why not? Are there any surprises in the sorted listings (by name and by value) that you can explain?

3. Test 3 should have at least 10 pairs of your choosing whose names are NOT capitalized and whose values are all words or phrases (no numerals). Make some of the values capitalized and some not. Ask yourself the same questions as noted for Test 2.

4. Test 4 should be identical to Test 3, except reverse the order of the items you gave in the URL for Test 3. Is the unsorted listing different from Test 3?

5. Tests 5 and 6 should be of your own choosing with lots of interesting data that will produce an interesting test.