[Solved] PHP Switch statements Error [closed]


You don’t actually use the brackets or default like that.

<?php

switch ($type) {
    case 'pm':
        // Do something when $type is 'pm'
        // This can be multiple statements
        break;

    case 'notification':
        // Do something when $type is 'notification'
        // This can be multiple statements
        break;

    default:
       // Do something else
       break;
}

You only add default once, for the code that will execute if none of the other cases are executed. The “case: ‘pm’:” section is starting a block that will go until the break statement exits it. If there is no break statement it will enter the next block (in this case notification).

Here’s a link to PHP’s website that has some more examples and details about how those statements work.

solved PHP Switch statements Error [closed]