The switch statement in php is used to perform different actions based on different conditions. Its usage syntax is "switch (expression){case label1:expression = label1 break;case label2:...}".
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
What does the switch statement in php mean?
The switch statement is used to perform different actions based on different conditions.
Switch Statement
If you want to selectively execute one of several blocks of code, use the Switch statement.
Use the Switch statement to avoid lengthy if..elseif..else code blocks.
Syntax
switch (expression) { case label1: expression = label1 时执行的代码 ; break; case label2: expression = label2 时执行的代码 ; break; default: 表达式的值不等于 label1 及 label2 时执行的代码; }
Working principle:
<?php $favfruit="orange"; switch ($favfruit) { case "apple": echo "Your favorite fruit is apple!"; break; case "banana": echo "Your favorite fruit is banana!"; break; case "orange": echo "Your favorite fruit is orange!"; break; default: echo "Your favorite fruit is neither apple, banana, or orange!"; } ?>
PHP Video Tutorial"
The above is the detailed content of What does the switch statement in php mean?. For more information, please follow other related articles on the PHP Chinese website!