PHP Control Statement If ... else_php Tutorials

Source: Internet
Author: User
The If, ElseIf, and ELSE statements are used to perform different actions based on different conditions.

Conditional statements

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.

If...else statements

Executes a piece of code when the condition is established, and executes another piece of code when the condition is not true

ElseIf statements

Used in conjunction with If...else to execute a block of code when one of several conditions is established

If ... Else statement

Use the If....else statement if you want to execute some code when a condition is set up and execute another code when the condition is not true.

Grammar

if (condition)  code to being executed if condition is True;else  

Instance

If the current date is Friday, the following code will output "a nice weekend!", otherwise it will output "a nice day!" :

     ";   echo "has a nice weekend!";  echo "See you on monday!";  }? >

ElseIf statements

If you want to execute code when one of several conditions is true, use the ElseIf statement:

Grammar

if (condition)  code to being executed if condition is true;elseif (condition)  code to being executed if condition is TR Ue;else  

Instance

If the current date is Friday, the following example outputs "a nice weekend!", and if it is Sunday, the output "has a nice sunday!", otherwise the output "has a nice day!" :

     echo "a nice day!"; ? >


http://www.bkjia.com/PHPjc/446732.html www.bkjia.com true http://www.bkjia.com/PHPjc/446732.html techarticle the If, ElseIf, and ELSE statements are used to perform different actions based on different conditions. Conditional statements when you write code, you often need to perform different actions for different judgments. You can ...

  • 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.