Switch Case Example

<?php
$day = "Monday";

switch ($day) {
case "Monday":
    echo "Start of the week!";
    break;
case "Friday":
    echo "Weekend is near!";
    break;
default:
    echo "Just another day.";
} ?>

Explanation:

  • switch is an alternative to multiple if-else statements.
  • If $day = "Monday", output will be Start of the week!

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *