Home > Backend Development > PHP Tutorial > PHP introductory basic tutorial PHP process control

PHP introductory basic tutorial PHP process control

WBOY
Release: 2016-07-25 09:00:16
Original
1059 people have browsed it
This section introduces PHP process control to you. PHP has three major process controls: sequence control, branch control, and loop control. It is recommended that you have a firm grasp of them.

PHP has three major process controls: sequence control, branch control, and loop control. 1. Sequential control: It means that 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 syntax structure: if(conditional expression){ Statement; //....; } Tip: No matter how complex the conditional expression is, it will ultimately be true or false;

Example 1,

<?php
a=11;
if(a>10){
  echo "a>10";
}//by bbs.it-home.org
Copy after login

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 can be omitted

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;

} Notice: 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 point: The program is first configured in case order. If none is matched, the contents of the default statement will be executed until break is encountered, and then the switch will exit;

Comparison of if and switch branches: if judges a certain range, and switch judges a point, so we can select them like this: Application scenario: When the branch is a few points (such as judging the direction of a tank), you should use switch. If the branch is a judgment of several areas (range), consider using if.

For related content about PHP control process control, you can also refer to the introduction in the PHP documentation: If...else, PHP loop, switch.

Thank you for paying attention to the PHP introductory tutorials. This series of PHP basic tutorials will help PHP newbies quickly master the PHP programming language. Programmer's Home will continue to launch PHP-related tutorials for everyone, and I wish you all the best in your learning and progress!



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