1. Create an associative array, to reflect data in the following table. Store the array in a variable called $electives. (see pages 44 and 45 in course text) Key Value CSIS-335 Graphical User Interface Programming SIS-336 C#.Net Programming CSIS-341 System and Network Administration CSIS-360 Linux Programming and Developmen 2. Using a foreach loop, write code that will display a hyperlink for each name in the table, e.g CSIS-335 CSIS-336. (see sample code, get-1.php on page 237 in course text; see sample code for-each-loop.php on page 92 in course text book). 3. Insert code to check if the key collected, using the query string, exists in the electives array. 4. Insert code that will cause the phrase “Select a course” to be displayed, if key in the query string does not exist. Test this by entering CSIS-152 in query string. Capture the outcome with a screenshot.
Objectives
– Demonstrate use of associative arrays
- Demonstrate knowledge of use of $_GET super global variable in data validation
- Demonstrate handling of missing data in $_GET
PHP $_GET is a PHP super global variable that can be used to collect form data after submitting an HTML
form with method="get". The PHP $_GET super global variable can be used to collect data sent in the
URL.
Task: You will modify given code, part-2.php, to collect a course number and display its title. For
instance, user will click on the hyperlink CSIS152, and this will cause the corresponding title
“Introduction to Computers and
1. Create an associative array, to reflect data in the following table. Store the array in a variable
called $electives. (see pages 44 and 45 in course text)
Key |
Value |
CSIS-335 |
Graphical User Interface Programming |
SIS-336 |
C#.Net Programming |
CSIS-341 |
System and Network Administration |
CSIS-360 Linux |
Programming and Developmen |
2. Using a foreach loop, write code that will display a hyperlink for each name in the table, e.g
CSIS-335 CSIS-336. (see sample code, get-1.php on page 237 in course text; see sample code
for-each-loop.php on page 92 in course text book).
3. Insert code to check if the key collected, using the query string, exists in the electives array.
4. Insert code that will cause the phrase “Select a course” to be displayed, if key in the query string
does not exist. Test this by entering CSIS-152 in query string. Capture the outcome with a
screenshot.
modify the given code:
<?php
$electives = [
];
= $_GET[' '] ?? '';
$valid = array_key_exists($, $electives);
if ($valid) {
} else {
}
?>
<?php foreach ($electives as $key => $value) { ?>
<a href="step-2.php? =<?= $key ?>"><?= $key ?></a>
<?php } ?>
<h3><?= ?></h3>
Trending now
This is a popular solution!
Step by step
Solved in 2 steps