Assignment 3
1
Create a new PHP script and define the following two-dimensional a
ay:
$products = [ [
'type' => 'electronics',
'name' => 'Audio Technica ATH-M50x',
'price' => 119.99,
'quantity' => 2 ],
[
'type' => 'electronics',
'name' => 'Sennheiser HD 202 II',
'price' => 24.50,
'quantity' => 5 ],
[
'type' => 'electronics',
'name' => 'GPX HM3817DTBK Micro System',
'price' => 135.99,
'quantity' => 1 ],
[
'type' => 'electronics',
'name' => 'Samsung MX-J XXXXXXXXXXChannel 230 Watt System',
'price' => 117.99,
'quantity' => 4 ],
[
'type' => 'electronics',
'name' => 'M-Audio Bass Traveler',
'price' => 29.00,
'quantity' => 9 ],
[
'type' => 'electronics',
'name' => 'HLED Strip light kit',
'price' => 17.95,
'quantity' => 5 ],
[ 'type' => 'movies', 'name' => 'Spectre', 'price' => '19.99', 'quantity' => 0 ],
[
'type' => 'movies',
'name' => 'Finding Dory',
'price' => 19.99,
'quantity' => 4 ],
[
'type' => 'movies',
'name' => 'Terminator: Genisys',
'price' => 14.95,
'quantity' => 3 ],
[
'type' => 'movies',
2
'name' => 'Interstellar',
'price' => 12.00,
'quantity' => 4 ],
[
'type' => 'movies',
'name' => 'Transformers: Age of Extinction',
'price' => 9.95,
'quantity' => 7 ],
[
'type' => 'movies',
'name' => 'Eye in the Sky',
'price' => 14.95,
'quantity' => 6 ],
[ 'type' => 'movies', 'name' => 'Venom', 'price' => '22.99', 'quantity' => 0 ],
[
'type' => 'movies',
'name' => 'The spy who dumped me',
'price' => 29.00,
'quantity' => 8 ],
[
'type' => 'movies',
'name' => 'Mamma Mia, Here We Go Again',
'price' => 22.99,
'quantity' => 4 ],
[
'type' => 'electronics',
'name' => 'M-Audio Bass Traveler',
'price' => 29.00,
'quantity' => 5 ],
[
'type' => 'video-games',
'name' => 'Battlefield 1',
'price' => 59.99,
'quantity' => 3 ],
[
'type' => 'video-games',
'name' => 'Overwatch',
'price' => 40.00,
'quantity' => 1 ],
[
'type' => 'video-games',
'name' => 'Gears of War 4',
'price' => 59.99,
'quantity' => 8 ],
[
'type' => 'video-games',
3
'name' => 'Titanfall 2',
'price' => 59.99,
'quantity' => 7 ],
[
'type' => 'video-games',
'name' => 'Sid Meier\'s Civilization VI ',
'price' => 59.99,
'quantity' => 4 ],
[
'type' => 'video-games',
'name' => 'The Sims 4',
'price' => 39.99,
'quantity' => 2 ],
[
'type' => 'video-games',
'name' => 'Grand Theft Auto V',
'price' => 59.99,
'quantity' => 7 ] ];
_____________________________________________________________________
Display the following information:
1. name, type, and price of each product.
2. name, type, and price of each product with a price greater than 30.
3. name, type, and price of each electronics item with a price greater than 30.
4. Revenue generated by each product is calculated by multiplying price and quantity:
evenue = price * quantity. Display the revenue generated by each item ( display name,
price, quantity, revenue) and the total revenue.
5. Find the revenue generated by electronics items (display name, type, price, quantity,
evenue).
Submit a single PHP code that generates output for each of the five parts.
You may use a loop for each part or use a single loop to extract data to generate each
output.
You may use functions to organize your code.
4
You may use the "Example: Use a table to display a
ay elements" document as a
guide to create a sample output similar to the following:
Example 1: Enrollment Data
Course Enrolled Capacity
";
/* Each element( $course ) is an a
ay.
XXXXXXXXXXUse a loop to append table cells to $tRow string using elements of
XXXXXXXXXXthe $course a
ay.
*
XXXXXXXXXXforeach($course as $c) {
$tRow .= " ".$c."
";
}
close the tr element
$tRow .= "";
Display table row
XXXXXXXXXXecho $tRow;
}
?
Example 2: Semester Plan
"COMPSCI", "course" => 382, "credits" => 3, "category" => "Elective"],
["subject" => "COMPSCI", "course" => 223, "credits" => 3, "category" => "Core"],
["subject" => "MATH", "course" => 250, "credits" => 5, "category" => "Unique"]
];
?
Subject Course# Credits Category
";
/* Each element $s is an associative a
ay.
XXXXXXXXXXUse a loop to append table cells to $tRow string using elements of
XXXXXXXXXXthe a
ay $s.
*
XXXXXXXXXXforeach($s as $key => $value) {
$tRow .= " ".$value."
";
}
close the tr element
$tRow .= "";
Display table row
XXXXXXXXXXecho $tRow;
}
?>