Home >Backend Development >PHP Problem >Write down what kind of process control structures there are in php

Write down what kind of process control structures there are in php

(*-*)浩
(*-*)浩Original
2019-09-10 09:56:392378browse

Any programming language is composed of many statements, and the PHP language is no exception. These statements include assignments, function calls, loop statements, empty statements, etc. We can also encapsulate several statements into statement groups. Statement groups It can also be regarded as a line statement by itself. Language structure is the core part of the program, and any functional module cannot do without it.

Write down what kind of process control structures there are in php

Definition of process control

Process control is a means of controlling a program. If the program has no flow Without control, there would be no programming language. Most programs are not controlled by linear execution statements. If the program needs to communicate with the user, the execution sequence must be determined based on user input, and the code may even need to be executed repeatedly. These are all inseparable from process control.

There are three basic program structures in PHP: sequential structure, branch structure, and loop structure

Sequential structure (Recommended learning: PHP Programming From entry to master)

Sequential structure is the most commonly used statement structure, such as assignment statements, and its execution order is from top to bottom, sequentially.

<?php
//实现$a和$b的值互换
$a=3;
$b=4;
$c=$a;
$a=$b;
$b=$c;
echo&#39;$a=&#39;.$a;
echo"<br/>";
echo&#39;$b=&#39;.$b;
?>

Branch structure

The branch structure is also called the conditional structure. It selects the execution path based on clear conditions, rather than strictly following the order. In practical programming The appropriate branch statement must be selected according to the program flow, which changes the executed program according to the result of the condition.

<?php
$t=date("H");
if ($t>"18") {
echo "晚上好!";
}
?>

Loop structure

What computers are best at is repeatedly performing certain operations according to conditions. Its characteristic is that when a given condition is established, it is executed repeatedly until the condition is not established. , this condition becomes a loop condition, and the repeatedly executed program segment becomes the loop body.

php provides three types of loops: while loop, do-while loop, and for loop

<?php
$x=0;
while($x<=3) {
echo "这个数字是:$x <br>";
$x++;
}
?>

<?php
for ($y=5; $y<=10; $y++) {
echo "数字是:$y";
echo"<br/>";
}
?>

The above is the detailed content of Write down what kind of process control structures there are in php. For more information, please follow other related articles on the PHP Chinese website!

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