The best PHP If ... Else Statements Tutorial In 2024, In this tutorial you can learn PHP conditional statements,PHP - if statement,Examples,PHP - if ... else statement,Examples,PHP - if ... else if .... else statement,Examples,PHP - switch statement,
Conditional statement used to perform different actions based on different conditions.
When you write code, you often need to perform different actions for different judgment. You can do this using conditional statements in the code.
In PHP, we provide the following conditional statement:
if statement is used to execute code only when a specified condition is met.
if (条件) { 条件成立时要执行的代码; }
If the current time is less than 20, the following example will output "Have a good day!":
Execute a block of code when condition is met, another piece of code execution condition is not satisfied, use the if /en/en else statement.
If the current time is less than 20, the following example will output "Have a good day!", Otherwise output "Have a good night!":
Execute a block of code if one of several conditions, use the if /en/en else if /en. else statement. .
If the current time is less than 10, the following example will output "Have a good morning!", If the current time is not less than 10 and less than 20, the output, otherwise the output "Have a good night!" "Have a good day!":
switch statement will explain in the next chapter.