[CODE lang="php" title="PHP"]<?php
$students = [
['name' => 'Jay', 'course' => 'Computer Engineering', 'gender' => 'Male', 'PRELIM' => 1.12, 'MIDTERM' => 1.21, 'FINALS' => 1.55, 'colleges' => 'CoEng'],
['name' => 'Mark', 'course' => 'Electronics Engineering', 'gender' => 'Male', 'PRELIM' => 1.61, 'MIDTERM' => 1.19, 'FINALS' => 1.92, 'colleges' => 'CoEng'],
['name' => 'Kris', 'course' => 'Tourism Management', 'gender' => 'Female', 'PRELIM' => 1.80, 'MIDTERM' => 1.49, 'FINALS' => 1.23, 'colleges' => 'CHI'],
['name' => 'Mae', 'course' => 'Hospital Management', 'gender' => 'Female', 'PRELIM' => 1.10, 'MIDTERM' => 1.02, 'FINALS' => 1.18, 'colleges' => 'CHI' ],
['name' => 'Danny', 'course' => 'Business Administration', 'gender' => 'Male', 'PRELIM' => 1.90, 'MIDTERM' => 1.85, 'FINALS' => 1.51, 'colleges' => 'COBA' ],
['name' => 'Karl', 'course' => 'Office Administration', 'gender' => 'Male', 'PRELIM' => 1.18, 'MIDTERM' => 1.74, 'FINALS' => 1.36, 'colleges' => 'COBA' ],
['name' => 'Yow', 'course' => 'Civil Engineering', 'gender' => 'Male', 'PRELIM' => 1.58, 'MIDTERM' => 1.25, 'FINALS' => 1.09, 'colleges' => 'CoEng' ],
['name' => 'Sarah', 'course' => 'Hotel Management', 'gender' => 'Female', 'PRELIM' => 1.93, 'MIDTERM' => 1.38, 'FINALS' => 1.14, 'colleges' => 'CHI' ],
['name' => 'Kaye', 'course' => ' Hospital Management', 'gender' => 'Female', 'PRELIM' => 1.44, 'MIDTERM' => 1.32, 'FINALS' => 1.85, 'colleges' => 'CHI' ],
['name' => 'Jake', 'course' => 'Hotel Management', 'gender' => 'Male', 'PRELIM' => 1.2, 'MIDTERM' => 1.01, 'FINALS' => 1.11, 'colleges' => 'CHI' ],
['name' => 'Mike', 'course' => 'Computer Engineering', 'gender' => 'Male', 'PRELIM' => 1.14, 'MIDTERM' => 1.71, 'FINALS' => 1.76, 'colleges' => 'CoEng' ],
['name' => 'Kimmy', 'course' => 'Civil Engineering', 'gender' => 'Female', 'PRELIM' => 1.04, 'MIDTERM' => 1.17, 'FINALS' => 1.13, 'colleges' => 'CoEng' ],
['name' => 'Jenny', 'course' => 'Tourism Management', 'gender' => 'Female', 'PRELIM' => 1.33, 'MIDTERM' => 1.22, 'FINALS' => 1.01, 'colleges' => 'CHI' ],
['name' => 'Alaiza', 'course' => 'Office Administration', 'gender' => 'Female', 'PRELIM' => 1.22, 'MIDTERM' => 1.72, 'FINALS' => 1.63, 'colleges' => 'COBA' ],
['name' => 'Nikki', 'course' => 'Business Administration', 'gender' => 'Female', 'PRELIM' => 1.11, 'MIDTERM' => 1.28, 'FINALS' => 1.75, 'colleges' => 'COBA' ],
['name' => 'Ben', 'course' => 'Electronics Engineering', 'gender' => 'Male', 'PRELIM' => 1.16, 'MIDTERM' => 1.49, 'FINALS' => 1.05, 'colleges' => 'CoEng' ],
['name' => 'Princess', 'course' => 'Human Resource', 'gender' => 'Female', 'PRELIM' => 1.88, 'MIDTERM' => 1.42, 'FINALS' => 1.77, 'colleges' => 'COBA' ],
['name' => 'Rudy', 'course' => 'Human Resource', 'gender' => 'Male', 'PRELIM' => 1.15, 'MIDTERM' => 1.40, 'FINALS' => 1.01, 'colleges' => 'COBA' ]
];
//COENG
echo 'The TOP 3 students on CoEng are: <br />';
$average_arr = array();
foreach ($students as $studentCoEng) {
if ($studentCoEng['colleges'] == 'CoEng'){
$average = $studentCoEng['PRELIM'] + $studentCoEng['MIDTERM'] + $studentCoEng['FINALS'];
$average = $average / 3;
$average_arr[$studentCoEng['name']] = $average;
$course = $studentCoEng['course'];
}
}
asort($average_arr);
$ranknum = 1;
foreach ($average_arr as $key => $value) {
echo "TOP $ranknum " . $key . '----- with an average of -----' . $value . " $course" .'<br />';
$ranknum += 1;
}
?>[/CODE]
/*
Problem solved. Pano po kaya to mag stop sa TOP 3 lang? Umaabot sya gang TOP 6 eh.
*/
Then parehas po lahat ng course nila eh iba iba po ang course sa College of Engineering o CoEng.
DESIRED OUTPUT:
OUTPUT NA NANGYAYARI:
Puro Elec. Eng. yung course
Maraming salamat po.