Alternative notation for Process Control

Source: Internet
Author: User

PHP provides some alternative syntax for process control, including if, while, for,foreach , and switch. The basic form of substitution syntax is to replace the left curly brace ({) with a colon (:) and the right curly brace (}) into endif;,endwhile;,endfor;,Endforeach; and Endswitch;.

<php  if ($a  = =  5 ):  ?  >is to5<php  endif;  ? >

In the example above, the HTML contents "A is equal to 5" are nested in an if statement with an alternate syntax. The contents of the HTML are $a displayed only at equals 5 o'clock.

Alternative syntax can also be used in else and ElseIf . The following is an example of an if structure, including ElseIf and else , written in alternate syntax format:

<? PHP if $a  = =  5):    echo  "a equals 5 "    ; echo  " ..." ; ElseIf $a  = =  6):    echo  "a equals 6 "    ; echo  "!!!"  ; else:    echo  "A is neither 5 nor 6" ; endif ;? >

Note: It is not supported to mix two syntaxes within the same control block.

Use and or replace if else

isset($aa) andPrint("AA is set") orisset($as) andPrint("As is set") orPrint("as Not set");//equivalent toif(isset($aa))    Print("AA is set");ElseIf(isset($as))    Print("As is set");Else    Print("as Not set");

Alternative notation for Process Control

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.