switch case

Javascript: Switch Case

Switch case is used as an alternative to if-else-elseif. Switch case is a conditional statement used to perform different actions based on different conditions. JavaScript Switch Case Syntax Javascript switch case syntax is similar to php switch case. As an example below, we switch based on condition: switch(val) { case 1: alert("executing case 1"); break; case 2: alert("executing case 2"); break; default: alert("executing default case"); } The above code is equivalent to javascript if-then-else below:  

PHP: Switch Case

Switch case used as an alternative to if-else-elseif to make it simpler to write conditions that are long and repeative. We use PHP Switch case as follows for the example mentioned earlier: <?php$sunlight = 0;?> <?phpswitch ($sunlight){    case "0":        echo "sunlight not present";        break;    case "1":        echo "sunlight present";        break;            default:        echo "Not sure about sunlight";        break;    }?>