May 10, 2021 PHP
This section describes PHP if... The use of else statements, through which you can selectively execute snippets of code.
Conditional statements are used to perform different actions based on different conditions.
When you write code, you often need to perform different actions for different judgments. You can use conditional statements in your code to accomplish this task.
In PHP, the following conditional statements are provided:
The if statement is used to execute code only when the specified condition is established.
If the current time is less than 20, the following example outputs "Have good day!" :
If one piece of code is executed when the condition is established and another piece of code is executed when the condition is not, use if.... Else statement.
The meaning of the statement is: code when the condition is true, code when the condition is true, and code when the condition is false, code when the condition is not true, the syntax is as follows:
If the current time is less than 20, the following example outputs "Have a good day!" or "Have a good night!" :
To execute a block of code when one of several conditions is established, use if.... e lse if... Else statement.
If the current time is less than 10, the following instance outputs "Have a good morning!", or "Have a good night!" if the current time is not good less than 10 and less than 20. :
In the next section, you'll learn more about switch statements.