$test1 = 7;
$test2 = 1;
$test3 = 3;
$total = $test1 $test2 $test3;
$isPassed = ( $total >= 10 && $test >= 2 ) ? true : false;
echo ( $isPassed ) ? "Passed" : "Not Passed";
I want to make that second condition is such that a student cannot pass the exam if on one of these tests he gets a grade that is lower than or equal to number 2. How can I code that?
CodePudding user response:
You can add them all to an array then use min()
.
//preferably store all of the test scores in an array
//instead of a separate variable for each one.
$test_scores = [$test1, $test2, $test3];
$total = array_sum($test_scores);
//you don't need the ternary because this expression will
//return true/false anyways
$isPassed = ($total >= 10 && min($test_scores) > 2);
CodePudding user response:
This helped! I just didn't remember that... Thank you!