Back to questions
JuniorTheoryCommon
What does the program print?
<?php
$score = 85;
if ($score > 50) {
echo 'C';
} elseif ($score > 80) {
echo 'A';
} else {
echo 'F';
}
echo "\n";C
- Expecting
Abecause 85 is above 80: the conditions are tried from the top, and the first true one,$score > 50, wins. - Expecting several branches to print: an
if/elseif/elsechain runs exactly one branch and then jumps past its end.
- How would you reorder the conditions so that a score of 85 prints
A? - What does the program print when
$scoreis30?