What's new

PHP PHP CODE

Status
Not open for further replies.

fuzzywubby

Forum Guru
Joined
Sep 20, 2018
Posts
4,587
Solutions
2
Reaction
1,865
Points
1,225
[CODE lang="php" title="PHP CODE"]<? php
$students2A = [
['name' => 'Jay', 'section' => 'II-A', 'gender' => 'Male', 'Math' => 1.2, 'Science' => 2.0, 'Filipino' => 1.5, 'English' => 3.1],
['name' => 'Kris', 'section' => 'II-A', 'gender' => 'Female', 'Math' => 1.5, 'Science' => 1.5, 'Filipino' => 1.2, 'English' => 3.2],
['name' => 'Mae', 'section' => 'II-A', 'gender' => 'Female', 'Math' => 3.5, 'Science' => 1.9, 'Filipino' => 3.3, 'English' => 1.0],
['name' => 'Danny', 'section' => 'II-A', 'gender' => 'Male', 'Math' => 3.1, 'Science' => 1.0, 'Filipino' => 1.3, 'English' => 1.9],
['name' => 'Sarah', 'section' => 'II-A', 'gender' => 'Female', 'Math' => 1.3, 'Science' => 3.1, 'Filipino' => 1.8, 'English' => 3.5],
['name' => 'Kaye', 'section' => 'II-A', 'gender' => 'Female', 'Math' => 1.1, 'Science' => 2.9, 'Filipino' => 1.4, 'English' => 3.0],
['name' => 'Alaiza', 'section' => 'II-A', 'gender' => 'Female', 'Math' => 4.2, 'Science' => 2.4, 'Filipino' => 2.8, 'English' => 1.1],
['name' => 'Ben', 'section' => 'II-A', 'gender' => 'Male', 'Math' => 1.9, 'Science' => 1.3, 'Filipino' => 3.2, 'English' => 2.9]
];


foreach ($students2A as $student2A) {
if ($student2A ['Math'] <= 3.0){

}

} echo 'There are ' . count ($student2A) . ' students who PASSED Math in ' . ($student2A ['section']) . '<br />';

?>
[/CODE]
----------------------------
Desired output:
There are 5 students who passed math in II-A.
----------------------------
Patulog naman po, pano ko po maccount yung mga GRADE is <= 3.0? Then maishow ko po yung bilang pagtapos ng "There are " sa may output.
Ang output pi kase na lumalabas is
There are 8 students who passed math in II-A.
8 na student parin, hindi nacount yung 5 na pasado lang.

Salamat po.
 
Last edited:
yung foreach mo same var dat mag kaiba

example

foreach($arr as $var){
}

bawal

foreach($arr as $arr)
 
pag aralan mo ohhh

di lang ako sure sa section hahaha

sorry grade10 lang ako self study lang ehh hahah
Code:
<?php
$students2A = [
['name' => 'Jay', 'section' => 'II-A', 'gender' => 'Male', 'Math' => 1.2, 'Science' => 2.0, 'Filipino' => 1.5, 'English' => 3.1],
['name' => 'Kris', 'section' => 'II-A', 'gender' => 'Female', 'Math' => 1.5, 'Science' => 1.5, 'Filipino' => 1.2, 'English' => 3.2],
['name' => 'Mae', 'section' => 'II-A', 'gender' => 'Female', 'Math' => 3.5, 'Science' => 1.9, 'Filipino' => 3.3, 'English' => 1.0],
['name' => 'Danny', 'section' => 'II-A', 'gender' => 'Male', 'Math' => 3.1, 'Science' => 1.0, 'Filipino' => 1.3, 'English' => 1.9],
['name' => 'Sarah', 'section' => 'II-A', 'gender' => 'Female', 'Math' => 1.3, 'Science' => 3.1, 'Filipino' => 1.8, 'English' => 3.5],
['name' => 'Kaye', 'section' => 'II-A', 'gender' => 'Female', 'Math' => 1.1, 'Science' => 2.9, 'Filipino' => 1.4, 'English' => 3.0],
['name' => 'Alaiza', 'section' => 'II-A', 'gender' => 'Female', 'Math' => 4.2, 'Science' => 2.4, 'Filipino' => 2.8, 'English' => 1.1],
['name' => 'Ben', 'section' => 'II-A', 'gender' => 'Male', 'Math' => 1.9, 'Science' => 1.3, 'Filipino' => 3.2, 'English' => 2.9]
    ];

    $count = 0;
    foreach ($students2A as $student) {
         if ($student['Math'] <= 3.0){
            $count += 1;
         }
    
    }
    echo 'There are ' .  $count . ' students who PASSED Math in ' . $students2A[0]['section'] . '<br />';
    
?>
 
Last edited:
Status
Not open for further replies.

Similar threads

Back
Top