with red color I love sunset is not correct, the correct is Selectedcolor is my favorite color
<?php
$a = "red";
switch ($a) {
    case "green":
        echo "I love earth";
    break;

    case "blue":
        echo "The sky is blue";
    break;

    case "yellow" or "orange":
        echo "I love sunset";
    break;

    default:
        echo "Selectedcolor is my favorite color";
    break;
}
?>
        case "yellow" or "orange":

    or is a boolean operator, so its operands are cast to booleans if they aren't already. "yellow" and "orange" both get cast to true, so "yellow" or "orange" is equivalent to true or true which is in turn equivalent to true. So that case will always succeed if the previous ones don't.

    What you have is two separate cases.

        case "yellow":
        case "orange":

      Just in case it's not clear, you can have one operation apply to both those cases, since the first does not have a break; with it, e.g.:

          case "yellow":
          case "orange":
              echo "I love sunset";
          break;
      
        Write a Reply...