How to use if...elseif...else statement in PHP
This article will explain in detail how to use the if...elseif...else sentence in PHP. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
PHP conditional statement
Conditional statements are used to perform different actions based on different conditions
You can do this by using conditional statements in your code to perform different actions for different decisions.
In PHP, we can use the following conditional statement:
If statement-executes code if the specified condition is true
If...else statement-if the condition is true, the code is executed; if the condition is false, the code on the other end is executed
If...elseif....else statement-Select one of several blocks of code to execute
Switch statement-statement one of multiple code blocks to execute
PHP-if statement
The if statement is used to execute code when the specified condition is true.
Tip: this example will output "Have a good day!" if the current time (HOUR) is less than 20.
PHP-if...else statement
Use the if....else statement to execute code when the condition is true and another piece of code when the condition is false.
Example
Tip: this example will output "… day!", if the current time (HOUR) is less than 20, otherwise output "… night!".
PHP-if...elseif....else statement
Use the if....elseif...else statement to select one of several code blocks to execute.
Tip: this example will output "Have a good morning!", if the current time (HOUR) is less than 10, if the current time is less than 20, then output "Have a good day!". Otherwise, "Have a good night!" will be output.
This is the end of the article on "how to use if...elseif...else sentences in PHP". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.