Читать книгу PHP Programming for Beginners. Key Programming Concepts. How to use PHP with MySQL and Oracle databases (MySqli, PDO) - Sergey D Skudaev - Страница 16

Switch statement

Оглавление

The switch statement has the following syntax:


switch (variable) {

case label1:

code to be executed if variable =label1;

break;

case label2:

code to be executed if variable =label2;

break;

default:

code to be executed if variable is not equal any label;

}


A Switch Example:


$temperature_C=100;


Switch ($temperature_C) {


Case: 0

$message=“Water freezing point.”;


Break;


Case: 100

$message=“Water boiling point!”:


Break;

Default:


$message=“Neither freezing nor boiling point.”;

}


If we pass in our switch statement variable with the value of 100 we will get Output: “Water boiling point!”

If we pass 0 we will get Output: =“Water freezing point.”

Otherwise, we will get Output: “Neither freezing nor boiling point.”

PHP Programming for Beginners. Key Programming Concepts. How to use PHP with MySQL and Oracle databases (MySqli, PDO)

Подняться наверх