Alternative syntax in PHP

Source: Internet
Author: User

we often see a lot of strange php syntax in the wordpress template of a blog program, such as:<?phpif(Empty($GET _[' A ']):? ><font color= "Red" > Empty </font><?phpendif;?>for a lot of PHP enthusiasts have never seen Ah, what are these things? Are those blog developers doing their own php-like template language? Non-also, in fact, these are PHP syntax, but not commonly used, these are PHP process control of the alternative syntax. Here we will give you a detailed talk about PHP Process Control alternative syntax. What is an alternative syntax? In short, it is some kind of grammatical alternative notation. Is there an alternative syntax for those grammars in PHP? Process Control (including if, while, Forforeach,SwitchThese statements have alternative syntax. The basic form of the substitution syntax: the left curly brace ({) is replaced by a colon (:), replace the right curly brace (}) withendif;,Endwhile;,endfor;,Endforeach; AndEndswitch; for example:<?phpif($a<0):?>is negative pull<?phpendif;?>The above statement is equivalent to<?phpif($a<0) {?>is negative pull<?php}?>Why is the pure PHP code almost invisible? These grammars are a bit out of line with the C family tradition a bit different, we are not accustomed to this grammar, and is not very convenient for everyone is not accustomed to, and so the alternative to what is his use? Does the egg hurt? Existence is reasonable, it has its own usefulness, these grammars can be played in the PHP and HTML mixed page code inside. The benefits are as follows:1.make HTML and PHP hybrid page code cleaner and neater. A friend with code cleanliness is most afraid of a messy mix of code, with these no curly braces alternative syntax, you love clean friends happy to pee. 2.Process Control logic clearer, code easier to read to change someone else's PHP and HTML mixed code, open found, I wipe! It's so damn rubbish! If you use the alternative syntax, I think the garbage program developers are not too messy to write. 3.some friends from other basic language families, such as ASP, are more likely to use PHP. It's useless to talk for half a day, okay? How does this thing work? The alternative syntax for the IF statement is used as follows, as described previously:<?phpif($a= = 5):?> <div> equals 5</div><?phpElseIf($a= = 6):?> <div> equals 5</div><?phpElse:?> <div> not 5 is 6</div><?phpendif;?>While substitution syntax:<?php while(expr):?> <li> cycle Point what </li><?phpEndwhile;?>For substitution syntax:<?php for(EXPR1; expr2; expr3):?> <li> cycle Point what </li><?phpendfor;?>foreach substitution syntax:<?phpforeach(EXPR1):?> <li> cycle Point what </li><?phpEndforeach;?>switch substitution syntax:<?PHPSwitch($i): Case0:Echo"I equals 0";  Break;  Case1:Echo"I equals 1";  Break;  Case2:Echo"I equals 2";  Break; default:Echo"I am not equal to 0, 1 or 2";Endswitch;?>

Alternate syntax in PHP (GO)

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.