Home >Backend Development >PHP Problem >Usage of php conditional statement if..else
Usage of php conditional statement if..else
PHP - if...else statement
To execute a block of code when the condition is true, and to execute another block of code when the condition is not true, please use the if....else statement.
Syntax
if (条件) { 条件成立时执行的代码; } else { 条件不成立时执行的代码; }
If the current time is less than 20, the following example will output "Have a good day!", otherwise it will output "Have a good night!":
Example
<?php $t=date("H"); if ($t<"20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ?>
Output:
Have a good day!
For more PHP related knowledge, please visit PHP Chinese website!
The above is the detailed content of Usage of php conditional statement if..else. For more information, please follow other related articles on the PHP Chinese website!