What's new

PHP HELP, Sino po expert sa PHP?

Status
Not open for further replies.

fuzzywubby

Forum Guru
Joined
Sep 20, 2018
Posts
4,587
Solutions
2
Reaction
1,865
Points
1,225
Kakasimula palang kasi aralin yung php then yung prof ko binigyan agad ako ng tambak na acts then dec. 11 agad pasahan. Baka po pwede magpatulong sa mga experts po jan. Salamat po.
 
[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:
1607397814304.png


OUTPUT NA NANGYAYARI:
1607397904230.png

Puro Elec. Eng. yung course

Maraming salamat po.
 

Attachments

Last edited:
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' ]
];


    echo 'The TOP 3 students on CoEng are: <br />';

    $average_arr = array();
    $num = 0;
    for($i = 0 ; $i< count($students); $i++) {
        if($students[$i]['colleges'] == 'CoEng'){
            $average = $students[$i]['PRELIM'] + $students[$i]['MIDTERM'] + $students[$i]['FINALS'];
            $average = $average / 3;
            $average_arr[$num]['name'] = $students[$i]['name'];
            $average_arr[$num]['course'] = $students[$i]['course'];
            $average_arr[$num]['average'] = $average;
            $num += 1;
        }
    }
    usort($average_arr, function($a, $b) {
        return $b['average'] <=> $a['average'];
    });
    $rank = 1;
    for($i = 0 ; $i < count($average_arr) ; $i++) {
          echo "rank $rank".$average_arr[$i]['name'] ." with an av of ". $average_arr[$i]['average'] . " couse ". $average_arr[$i]['course']."<br />";
          $rank += 1;

          if($rank - 1 == 3){
              break;
          }
    }
?>

pag aralan mo hahaha

pag palitin mo lang line 39

return $b['average'] <=> $a['average']; high to low

return $a['average'] <=> $b['average']; low to high
 
Last edited:
Status
Not open for further replies.

Similar threads

Back
Top