Examples of alternative syntax for PHP process Control

Source: Internet
Author: User
Tags foreach mixed php and php code php foreach

  Phper will see a lot of strange PHP syntax, such as:
<?php if empty ($GET _[' a ')) as a template for WordPress-type Blog programs:
<font color = "Red" > Empty </font>
<?php endif
for a part of Phper have not seen these things at all? Are those blogging developers doing their own scripting language for PHP?
not also, in fact these are all PHP syntax, but not commonly used, these are PHP Process control alternative syntax.
Here is a detailed look at the alternative syntax for PHP process control. What is an alternative syntax? The
is simply the alternative way of writing some grammar.
does the syntax in PHP have an alternate syntax?
Process Control (including If,while,foreach,switch) has an alternative syntax for these statements.
The basic form of an alternative syntax:
The left curly brace ({) is replaced with a colon (:), and the right curly brace (}) is replaced with Endif;,endwhile;,endfor;,endforeach, and Endswitch
For example:

is a negative number

The above statement equals

is negative pull
Why is it almost invisible inside the pure PHP code?
These grammars are somewhat different from the C family tradition, and we are not accustomed to this syntax, and not very convenient
everyone is not accustomed to, and so the alternative to him what use? Does the egg hurt?
Existence is reasonable, it has its own usefulness, the syntax can be played in the PHP and HTML mixed page code inside. The benefits are as follows:
1. Make HTML and PHP mixed page code cleaner and more neat.
A friend with code cleanliness is most afraid of a mess of mixed code, with these no curly braces alternative syntax, you love clean friends happy to the urine shock.
2. Process Control logic clearer, code easier to read
to change someone else's PHP and HTML mix Code, open discovery, I rub! It's too damn rubbish! If you use the alternative syntax, I think the garbage program developers will not write too messy.
3. Some friends who are transferred from other classes of basic languages such as ASP will make PHP easier to use.
It's no use talking for half a day, okay? How does this thing work?
According to the use method described previously, the alternative syntax for the IF statement is used as follows:
<?php if ($a = =5):
<div> equals 5</div>
<?php elseif ($a = = 6):?
<div> equals 5</div>
PHP Else:
<div> not 5 is 6</div>
<?php endif
While substitution syntax:
<?php while (expr):? &G T
<li> Loop dot what </li>
<?php endwhile
for alternative syntax:
<?php for (expr1; expr2; expr3):? > <li> Loop dot what </li>
<?php endfor;
foreach substitution syntax:
<?php foreach (expr1):?
<li > Loop dot what </li>
<?php endforeach;
Switch substitution syntax:
Switch ($i):
Case 0:
echo "I equals 0″;
Case 1:
echo "I equals 1″
Case 2:
echo "I equals 2″
echo "I am not equal to 0, 1 or 2″;

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.