Home >Backend Development >PHP Problem >Step aside, here comes the single branch structure (source code attached)
The last article introduced you to "Understanding of php7 (with detailed tutorial)". This article continues to introduce to you the process control and branch structure-single branch structure. Not much to say, let's talk about it together Let's see! ! !
#1. What is process control?
The control of the execution flow of program code is called process control;
2. What is a process?
The order of program execution is the process;
3. Classification of processes?
Sequential structure (the top-down execution process of the program is a sequential structure, and all programs default to a sequential structure)
Branch structure (during the execution of the program, different choices are often made based on different running results, or part of the code is ignored. This execution result is called a branch structure)
Loop structure (the computer repeatedly executes one thing or a piece of code)
4. Branch structure classification:
Single branch structures are divided into Two formats:
The code is as follows:
<?php /******单行分支结构 ******/ //定义一个变量 $pome = true; //进行判断 if($pome == false) echo '白日依山尽,黄河入海流<br/>'; echo '欲穷千里目<br/>'; echo '更上一层楼<br/>'; //格式2 $pome = false; if($pome == false){ echo '窗前明月光<br/>'; echo '疑是地上霜<br/>'; } echo '举头望明月<br/>'; echo '低头思故乡<br>'; ?>
The running results are as follows:
In summary, the single branch structure format one:
if (conditional expression)
A PHP code
If the conditional expression is true, the first code after if will be executed;
If the condition is false, the first code after if will not be executed;
Note: The branch structure in this format can only control the first PHP statement after if
Format 2:
if (conditional expression) {
One PHP code
Two PHP codes
...
}The branch structure of this format can control all content in the {} area of a complete code block after if.
So you can use branch statements when you encounter statements that need to be executed repeatedly.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of Step aside, here comes the single branch structure (source code attached). For more information, please follow other related articles on the PHP Chinese website!