What are common pitfalls when using the switch statement in PHP, and how can they be avoided?

One common pitfall when using the switch statement in PHP is forgetting to include a break statement at the end of each case. This can cause unexpected behavior where multiple cases are executed. To avoid this, always remember to include a break statement after each case to ensure that only the intended case is executed.

$day = "Monday";

switch ($day) {
    case "Monday":
        echo "Today is Monday";
        break;
    case "Tuesday":
        echo "Today is Tuesday";
        break;
    // Add more cases here
    default:
        echo "Invalid day";
}