English explanation:
##*if * Pronunciation: [ɪf] Chinese explanation: if
Chinese explanation: Otherwise
##PHP conditional statement
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
<?php
$sun=100;
if($sun>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
<?php $sun=110; if($sun>200){ echo "$sun>200"; }else{ echo "$sun<200"; } ?>
##
if...elseif....else statement
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<?php
header("Content-type:text/html;charset=utf-8"); //设置编码
$sun=150;
if($sun>200){
echo "满足条件1";
}elseif($sun<180){
echo "满足条件2";
}else{
echo "都不满足条件";
}
?>
PHP - switch statement
We will learn the switch statement in the next section.