Step aside, here comes the single branch structure (source code attached)

慕斯
Release: 2023-03-10 08:26:01
Original
2092 people have browsed it

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! ! !

Step aside, here comes the single branch structure (source code attached)

#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 &#39;白日依山尽,黄河入海流<br/>&#39;;
    echo &#39;欲穷千里目<br/>&#39;;
    echo &#39;更上一层楼<br/>&#39;;
    
    
    
    //格式2
    $pome = false;
     if($pome == false){
         echo &#39;窗前明月光<br/>&#39;;
         echo &#39;疑是地上霜<br/>&#39;;
     }
     echo &#39;举头望明月<br/>&#39;;
     echo &#39;低头思故乡<br>&#39;;
?>
Copy after login

The running results are as follows:

Step aside, here comes the single branch structure (source code attached)

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template