What is the use of Switch statement in php
This article mainly shows you "what is the use of Switch sentences in php", the content is simple and clear, and I hope it can help you solve your doubts. Let me lead you to study and learn this article "what is the use of Switch sentences in php".
Switch statement
If you want to selectively execute one of several code blocks, use the Switch statement.
Long blocks of if..elseif..else code can be avoided by using Switch statements.
Grammar
Code executed when switch (expression) {case label1: expression = label1; code executed when break; case label2: expression = label2; break;default: the value of the expression is not equal to the code executed when label1 and label2;}
How it works:
Evaluate an expression (usually a variable) once
Compare the value of the expression with the value of case in the structure
If there is a match, execute the code associated with the case
After the code is executed, the break statement prevents the code from jumping into the next case to continue execution
If no case is true, use the default statement
Example
The above is all the content of the article "what is the use of Switch sentences in php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!