PHP ElseIf and else if difference

Source: Internet
Author: User

PHP ElseIf and else if difference

If, ElseIf, and ELSE statements are used to perform different actions based on different conditions.

Conditional statement
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 ($condition 1)   
  {  
 }  
  else   & nbsp
  if ($condition 2)   
  {  
 }  
  else   br>   {  
 }  
 //No More ElseIf () .  
  and   
  if ($condition 1)   
  {  
 }  
  ElseIf ($condition 2) & nbsp; 
  {  
 }  
  else  
  {  
 }  
<?php
$d =date ("D");
if ($d = = "Fri")
  echo "Have a nice weekend!";
ElseIf ($d = = "Sun")
  echo "Have a nice sunday!";
Else
  echo "Have a nice day!";
?


If...else Statement
Executes a piece of code when the condition is set, and executes another piece of code when the condition is not established
ElseIf statement
is used in conjunction with If...else, executing a code block if one of several conditions is true ... Else Statement
If you want to execute some code when a condition is set up, and execute some other code when the condition is not valid, use the If....else statement.
Syntax
if (condition)
  code to was executed if condition is true;
Else
  code to be executed if condition is false;

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.