Home  >  Article  >  Backend Development  >  Implementation Analysis of Process Control in PHP Basic Learning_PHP Tutorial

Implementation Analysis of Process Control in PHP Basic Learning_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:11:26845browse

PHP has three major process controls: sequence control, branch control, and loop control.

1. Sequential control: The program is executed step by step from top to next in order.

2. Branch control: Selective execution of the program. It is also divided into single branch, multiple branches, and multiple branches.

a. Single branch: basic grammatical structure:

if(conditional expression){

Statement;

 //....;

} Tip: No matter how complex the conditional expression is, it will ultimately be true or false;

eg:

a=11;

if(a>10){

echo "a>10";

}

b. Multi-branch: basic syntax:

if(conditional expression){

Statement;

 //....;

}else{

Statement;

 //....;

}

c, multiple branches: basic syntax:

if(conditional expression){

Statement; n statements;

}else if(conditional expression){

statement;n statements;

}elseif(conditional expression){

statement;n statements;

}eles{

statement;n statements;

} Tips: 1. Else if can have one or more. 2. The last else does not need to be

d, switch branch statement

switch(expression){

case constant 1:

Statement; n statements;

break;

Case constant 2:

Statement; n statements;

break;

case constant 3:

Statement; n statements;

break;

default:

  statement; n statements;

break;

} Note:

1. There are one to many case statements
2. The defaul statement does not need to be included (according to the business logic of your own code)
3. Usually, after the case statement, break is required to indicate exiting the switch statement
4. Type of constant (int, float, string, Boolean)

Key points: The program is first configured in case order. If none is matched, the content of the default statement will be executed until break is encountered, and the switch will exit;

Comparison of if and switch branch :

if is a judgment on a certain range, and switch is a judgment on a point, so we can select them like this:

Application scenario: When our branch is a few points (such as determining the direction of a tank), we should use swtich. If your branch is several areas (range) To judge, consider using if

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326903.htmlTechArticlePHP has three major process controls: sequence control, branch control, and loop control. 1. Sequential control: The program is executed step by step from top to next in order. 2. Branch control: Program selection...
Statement:
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