In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "what is the meaning of choosing a structural sentence in php", the content is simple and clear, and I hope it can help you solve your doubts. Let the editor lead you to study and learn what it means to choose a structural sentence in php.
In PHP, selecting a structural statement means making a judgment on some conditions to determine the statement that executes the specified code. The selection result statement is used to judge the given condition and control the flow of the program according to the result of the judgment.
This article operating environment: Windows10 system, PHP7.1 version, Dell G3 computer.
What is the meaning of the selective structure statement in php
Choosing a structural statement means that some conditions need to be judged to decide to execute the specified code.
The selection structure is used to judge the given conditions and control the flow of the program according to the result of the judgment.
Let's take a look at the commonly used selection control statements:
1. If single branch structure
The conditional judgment statement of single branch statement is also called single branch statement. When a certain condition is satisfied, some processing is carried out. For example, the output is adult only if it is 18 years old or older, otherwise there is no output. Specific syntax and examples such as:
Grammar
If (judgment condition) {Code snippet}
Example
If ($age > = 18) {echo' is an adult';}
In the above syntax, determine that the price adjustment you are a Boolean value, when the value is ture, execute the code snippet in "{}", otherwise no processing is performed. When there is only one statement in the contemporary code block, "{}" can be omitted.
2. If... Else statement
If... Else statements are also called double-branch statements. When certain conditions are met, one kind of processing is performed, otherwise another processing is performed. For example, to judge the age of a student, if he is 18 or older, he is an adult. Or a minor. The specific syntax and examples are as follows:
Syntax:
If (judgment condition) {code snippet 1;} else {code snippet 2;}
Example:
If ($age > = 18) {echo' is adult';} else {echo' underage';}
In the above syntax, code 1 is executed when the condition is ture, and snippet 2 is executed when the condition is false.
In addition, PHP also has a special operator: ternary and operator (also known as ternary operator), which can also complete if. The syntax and examples of the else statement are as follows.
Syntax:
Conditional expression? Expression 1: expression 2
Example:
Echo $age > = 18cm' Come of age': 'underage'
In the above syntax format, the value of the conditional expression is calculated first, and if true, the execution result of expression 1 is returned; if the value of the conditional expression is false. The execution result of expression 2 is returned.
It is worth mentioning that when expression 1 is the same as a conditional expression, it can be abbreviated, omitting the middle part. For example, if the student's age $age is a natural number (> = 0), the example is as follows:
Syntax:
Conditional expression?: expression 2
Example:
Echo $age?:' has not been born yet.
3. If... Elseif... Else statement
If... Elseif... Else statements are called multi-branch statements and are used for different processing for different situations. For example, a student's test scores are graded as excellent at 90 to 100, good at 80 to 90, medium at 70 to 80, passing at 60 to 70, and failing at less than 60. The specific syntax is as follows:
Grammatical structure:
If (condition 1) {code snippet 1;} elseif (condition 2) {code snippet 2;}... Elseif (condition n) {code snippet n;} else {code snippet 1;}
Example:
If ($score > = 90) {echo' excellent';} elseif ($score > = 80) {echo' good';} elseif ($score > = 70) {echo' medium';} elseif ($score > = 60) {echo' pass';} else {echo' fail';}
In the above syntax, snippet 1 is executed when condition 1 is ture; otherwise, snippet 2 is executed if condition 2 is ture, and so on; if all conditions are false, snippet 1 is executed.
The above is all the content of the article "what is the meaning of choosing structural 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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.