How is the IF related conditional statement in PHP understood to be used?

Source: Internet
Author: User
Tags learn php
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 statementIf...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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.