When we develop PHP pages, we sometimes need to read the information from the database or page according to different criteria before executing the corresponding statement. When it comes to this, we need to understand the use of some conditional statements in PHP. This article will give you a detailed introduction
in PHP
if condition judgment statement、
If...else Conditional StatementsAnd
If...elseif...else
Multi-conditional statementsSpecific use of the method.
Let's give you a detailed explanation of the specific code examples below.
First, the PHP if condition judgment statement
code example:
<?php$t=date ("H"), if ($t < ") { echo" current time is less than 20 o'clock, output this paragraph of text ";}? >
Access through the browser to determine the results such as:
The above code we can understand this, first use date to get the current time, and then use the IF statement to determine whether the current time is less than 20, if less than the ECHO output the specified statement. , the specified text is successfully output. (Recommended reference Online Course: "Learn PHP in the blink of an-php" in the third chapter content of the conditional statement)
Second, PHP if...else conditional judgment statement
The code examples are as follows:
<?php$t=date ("H"), if ($t < ") { echo" if judging if the current time is less than 20 to output this paragraph of text ";} else{ echo "otherwise output this piece of text";}? >
Access through the browser to determine the results such as:
The above code we can understand, first date to get the current time, and then when the $t less than 20 of the condition is true, the output "if judge if the current time is less than 20 output this paragraph of text" this statement, otherwise output another statement.
Three, PHP if...elseif....else multi-Conditional judgment statement
The code examples are as follows:
<?php$t=date ("H"), if ($t < "ten") { echo "Good Morning";} ElseIf ($t < ") { echo" Good Day ";} else{ echo "Good Evening";}? >
Accessed through the browser. Judging results such as:
If the current time is less than 10, execute the output "Good Morning" statement. If the current time is greater than 10 but less than 20, then the output "good day" statement is executed. The final current time does not meet the above two conditions, the output "good evening" this statement.
Then through the above about the PHP if else and other conditional statements of the relevant introduction, I hope to have the necessary friends have some help.