Source Code:
(back to article)
<?php // Example 1 $day = "Monday"; switch ($day) { case "Monday": echo "Today is Monday." . PHP_EOL; break; case "Tuesday": echo "Today is Tuesday."; break; case "Wednesday": echo "Today is Wednesday."; break; default: echo "Today is not Monday, Tuesday, or Wednesday."; } // Output: Today is Monday. // Example 2 $grade = 85; switch (true) { case $grade >= 90: echo "A"; break; case $grade >= 80: echo "B"; break; case $grade >= 70: echo "C"; break; case $grade >= 60: echo "D"; break; default: echo "F"; } // Output: B
Result:
Report an issue