// ================== TASK 3(a) ================== // ICT Module Code Processing using explode() and string functions if (isset($_GET['submit_modules']) && isset($_GET['modules']) && !empty($_GET['modules'])) { $input = $_GET['modules']; // Remove spaces and split by comma $cleanInput = str_replace(' ', '', $input); $moduleCodes = explode(',', $cleanInput); echo '

Module Details:

'; echo ''; echo ''; foreach ($moduleCodes as $code) { $code = trim($code); if (!empty($code) && strlen($code) >= 5) { $year = $code[3]; // 4th character (0-indexed) $nqfLevel = $code[4]; // 5th character (0-indexed) echo ""; echo ""; echo ""; echo ""; echo ""; } } echo '
Module CodeYear of OfferingNQF Level
$code$year" . "nd YearNQF Level $nqfLevel
'; } // ================== TASK 3(b) ================== // DateTime and Age Calculation function displayBirthdateAndAge($dateTime) { // Display in day/month/year format $formattedDate = $dateTime->format('d/m/Y'); // Calculate age $now = new DateTime(); $age = $now->diff($dateTime); $ageYears = $age->y; echo "

Birthdate: $formattedDate

"; echo "

Age: $ageYears years

"; } // Test with three DateTime objects $date1 = DateTime::createFromFormat('d-m-Y', '29-03-1980'); displayBirthdateAndAge($date1); $date2 = new DateTime(); displayBirthdateAndAge($date2); $date3 = DateTime::createFromFormat('d-m-Y', '31-12-1996'); displayBirthdateAndAge($date3); // ================== TASK 3(c) ================== // Array Operations - range(), rsort(), asort() // Create monthsNum array using range() $monthsNum = range(1, 12); // Create monthsString array $monthsString = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ); // Display mapping using for loop echo "

Months Mapping:

"; for ($i = 0; $i < count($monthsNum); $i++) { echo "{$monthsNum[$i]} - {$monthsString[$i]}
"; } // Invoke rsort() on monthsString rsort($monthsString); echo "

After rsort() on monthsString:

"; foreach ($monthsString as $month) { echo "$month
"; } // Create associative array $assocMonths = array( 1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December' ); echo "

Associative Array:

"; foreach ($assocMonths as $key => $value) { echo "$key - $value
"; } // Invoke asort() on associative array asort($assocMonths); echo "

After asort() on Associative Array:

"; foreach ($assocMonths as $key => $value) { echo "$key - $value
"; }