PHP Switch

The switch statement is similar to a series of IF statements on the same expression. It is used to execute one statement from multiple conditions.

switch ($num) {
    case '1':
        echo 'Number is 1';
        break;
    case '2':
        echo 'Number is 2';
        break;
    case '3':
        echo 'Number is 3';
        break;
    default:
        echo 'Number is neither 1,2, nor 3';
        break;
}

php switch statement flowchart