The difference between ElseIf else if

Source: Internet
Author: User
Tags parse error

It is recommended to use else if.

in PHP

(PHP 4, PHP 5)

ElseIf, as implied by this name, is the combination of if and else . As with else , it extends the if statement and can execute different statements when the original if expression FALSE value is. But unlike else , it only executes the statement when the ElseIf 's conditional expression value is TRUE .


It's important to note thatElseIfwith theelse ifIt is considered identical only if curly braces are used in a similar case. If you use a colon to defineif/ElseIfcondition, then you can't use two words.else if, or PHP will generate parsing errors

<?php

/* Incorrect method of use: */
if ($a>$b):
Echo$a."is greater than".$b;
else if ($a== $b): //will not compile
Echo"The above line causes a parse error.";
endif


/* Correct way to use: */
if ($a>$b):
Echo$a."is greater than".$b;
ElseIf ($a== $b): //Note the use of a word ElseIf
Echo$a."equals".$b;
Else
Echo$a."is neither greater than or equal to".$b;
endif

?>


The difference between ElseIf else if

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.