PHP - if...elseif....else statement
Please use if.... elseif...else statement to execute different code based on two or more conditions.
Syntax
if (条件) { 条件为 true 时执行的代码; } elseif (condition) { 条件为 true 时执行的代码; } else { 条件为 false 时执行的代码; }
If the current time (HOUR) is less than 10, the following example will output "Have a good morning!", if the current time is less than 20, then output "Have a good day!" . Otherwise, "Have a good night!" will be output:
Example
<?php $t=date("H"); if ($t<"10") { echo "Have a good morning!"; } elseif ($t<"20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ?>
Output:
Have a good morning!
For more PHP related knowledge, please visit PHP Chinese net!
The above is the detailed content of Usage of PHPelseif. For more information, please follow other related articles on the PHP Chinese website!