PHP Process Control Elseif/else if

Source: Internet
Author: User
Tags parse error
This article mainly introduces the PHP process Control elseif/else If, has a certain reference value, now share to everyone, the need for friends can refer to

This paper tries to use the basic Learning Master, please close this page

Read this article for 3 minutes, it's hard to understand.

(PHP 4, PHP 5, PHP 7)

ElseIf, as implied by this name, is the combination of if and else. As with else, it extends the IF statement and can FALSE execute different statements when the original if expression value is. But unlike else, it only executes the statement when the ElseIf's conditional expression value is TRUE . For example, the following code will display a bigger than B,a equal to B , or A is smaller than Baccording to the conditions:

<?PHPIF ($a > $b) {    echo "A is bigger than B";} elseif ($a = = $b) {    echo "A is equal to B";} else {    echo "A is smaller than B";}? >

There can be more than one ElseIf part in the same if statement, where TRUE the ElseIf portion of the first expression value (if any) is executed. In PHP, you can also write "else if" (two words), which behaves exactly like "ElseIf" (a word). There is a slight difference in the meaning of syntactic analysis (if you are familiar with C, the same behavior), but the bottom line is that both produce exactly the same behavior.

The ElseIf statement only precedes the IF and all previous ElseIf expression values FALSE , and the current ElseIf expression value is TRUE executed.

Note: It must be noted that ElseIf and else if you use curly braces in a similar case, it is only considered identical. If you use a colon to define the If/elseif condition, you cannot use the else if for two words, or PHP will produce parsing errors.

<?php/* incorrect usage methods: */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 usage: */if ($a > $b):    echo $a. "is greater than". $b; ElseIf ($a = = $b)://Note the ElseIf echo $a using a word    . "Equals". $b; else:    echo $a. "is neither greater than or equal to". $b; endif;? >

Related recommendations:

The else of PHP process Control

PHP Process Control if statement

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.