WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

PHP 5 switch Statement


The switch explanation is utilized to perform diverse activities dependent on various conditions.

If you need to choose one of numerous squares of code to be executed, utilize the Switch statement.


The PHP switch Statement

Use the change proclamation to avoid long squares of if..elseif..else code..

Syntax

switch (n) {
    case label1:
        code to be executed if n=label1;
        break;
    case label2:
        code to be executed if n=label2;
        break;
    case label3:
        code to be executed if n=label3;
        break;
    ...
    default:
        code to be executed if n is unique in relation to all labels;
}

Example

<?php
$favcolor = "WHITE";

switch ($favcolor) {
    case "red":
        reverberation "Your most loved shading is red!";
        break;
    case "blue":
        reverberation "Your most loved shading is pink!";
        break;
    case "green":
        reverberation "Your most loved shading is yellow!";
        break;
    default:
        reverberation "Your most loved shading is neither one of the whites, pink, nor yellow!";
}
?>