PHP if...else...elseif statement

English explanation:

##*if * Pronunciation: [ɪf]

Chinese explanation: if

else Pronunciation: [ɛls]

Chinese explanation: Otherwise


##PHP conditional statement

When you write code, you often want to perform different actions for different decisions. You can do this using conditional statements in your code.


In PHP, we can use the following conditional statements:

· if statement - If the specified condition is true, the code is executed

· if ...else statement - if the condition is true, execute the code; if the condition is false, execute the other end of the code

· if...elseif....else statement - select one of several code blocks To execute

· switch statement - statement one of multiple code blocks to execute


PHP - if statement

if statement is used to specify a condition Execute code when true.

Syntax

##if(

Condition

) {Execute when the condition is true

}

##Example

90){ echo "100>90"; } ?>

##if. . .else statement



## Use the if....else statement to execute code when a condition is true and another section of code when the condition is false.Syntax

if(

Condition){

Execute when the condition is true

} else {

Execute when the condition is false

}

Example

200){ echo "$sun>200"; }else{ echo "$sun<200"; } ?>

##


if...elseif....else statement

##if....elseif...else statement Select one of several code blocks to execute.

Syntax

if(Condition 1) {

## Execute when condition 1 is true

} elseif(

Condition 2) {

Executed when condition 2 is true

}

else{

Executed when the conditions are not met

}

Example

200){ echo "满足条件1"; }elseif($sun<180){ echo "满足条件2"; }else{ echo "都不满足条件"; } ?>


PHP - switch statement
We will learn the switch statement in the next section.


Continuing Learning
||
200){ echo "$sun>200"; }else{ echo "$sun<200"; } ?>
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!