Question: Part I Declare a one dimensional associative array that has at least 8 key/element pairs. Print out the array in table form. Print out the
Part I
Declare a one dimensional associative array that has at least 8 key/element pairs.
Print out the array in table form.
Print out the sorted array in table form.
Unset the second element in the sorted array.
Print out the reverse sorted array in table form.
Print out the array sorted by KEY value in table form.
Part II
Create a two dimensional array (the second dimension should be associative, with keys Name, Karma, and LastLogin, the first can be indexed (1-4). Or you can have both dimensions be associative) that contains the following information about users of your website:
| UserID | Name | Karma Score | Last Login |
| 1 | Doe | 45 | 2012-08-30 |
| 2 | Smith | 123 | 2012-09-02 |
| 3 | Chan | 1 | 2011-12-23 |
| 4 | Zee | 15 | 2012-07-01 |
Print out the array sorted by user-id
Print out the array sorted by Login (use the strtotime() function)
Print out only users who have Karma score > 10, sorted by Karma score in descending order.
Add a form to your php file that has a user put in a name and id, with the method post. If the name exists, add 5 to the karma score. If the name does not, add an element to the array with karma score of 1, and today's date (use the date function). Print out the new array.
EXTRA CREDIT: The way the assignment is set up above, you can add one person or add 5 to one person, but the array otherwise stays the same. If you then post again, it will start off with the old original array. For extra credit, use a hidden element in the form that allows a user to keep adding to the karma score or to keep adding new users.
This is a web page development lab, using php and html. A reference was given below
Passing Array Variables using POST or GET with PHP
August 27th, 2013 43,700
Share:
A convenient way to pass a single or multidimensional (possible utf-8) array is to serialize it ("convert it to a string") and pass it using a hidden input. After post or get, unserialize string variable, so the original array will be available.
How to serialize the array
Store the value in a hidden input. Try the following:
| 1 2 3 4 |
id="str_var" name="str_var" value="">; |
Unserialize (after post or get)
Use something like this
| 1 2 | $str_var = $_POST["str_var"]; $array_var = unserialize(base64_decode($str_var)); |
Encode URL
In case you have to create with code (e.g. javascript) the url to get, remember to encode it as a valid url:
| 1 2 3 |
id="str_var" name="str_var" value="">; |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
