Home > Backend Development > PHP Problem > Let's learn about the nested if else if structure of PHP process control! ! !

Let's learn about the nested if else if structure of PHP process control! ! !

慕斯
Release: 2023-03-09 21:52:01
Original
2642 people have browsed it

The previous article introduced you to "How to use PHP to implement a simple registration and login system (with source code)". This article continues to introduce to you the nested if else if structure of PHP process control:

Let's learn about the nested if else if structure of PHP process control! ! !

The if else is structure is as follows:

<?php
if(判断语句1){
执行语句体1
else if(判断语句体2){
}
}
?>
Copy after login

The above structure indicates:

If the value of judgment statement 1 is true , then execute statement body 1, and enter the subsequent code segment after the execution is completed.

Otherwise, go to the following judgment statement 2 (else if). If judgment statement 2 is true, execute statement body 2.

Otherwise, go to the judgment statement n (else if). If judgment statement 2 is true, execute statement body n.

If none of them match, the else statement will be executed. This kind of loop nesting may not contain the else statement, that is, only if, else if statement

The following code is used as an example:

<?php
//定义一个随机变量,抵达时间,随机0点至23点
$dida = rand(0,23);

if($dida > 6 && $dida < 10){
    echo &#39;人生若只如初见&#39;;
}elseif($dida >=19 && $dida < 22){
    echo &#39;何事秋风悲画扇&#39;;
}elseif($dida >=22 && $dida < 23){
    echo &#39;等闲变却故人心&#39;;
}else{
    echo &#39;却道故心人易变&#39;;
}
?>
Copy after login

The running results are as follows:

Lets learn about the nested if else if structure of PHP process control! ! !

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of Let's learn about the nested if else if structure of PHP process control! ! !. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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