PHP中的替代语法介绍
今天看了一下wordpress的代码,里面有些少见的php替代语法,
<?phpelse:?>
<divclass="entry-content">
<?phpthe_content(__('Continuereading<spanclass="meta-nav">→</span>','thebox'));?>
<?phpwp_link_pages(array('before'=>'<divclass="page-links">'.__('Pages:','thebox'),'after'=>'</div>'));?>
</div><!--.entry-content-->
<?phpendif;?>
else后面的冒号和endif代表啥?菜鸟一个,没有见过,所以就google了一下,才明白这是php的替代语法,
冒号(:)等价于左花括号({),endif等价于右花括号(});
举个例子吧:
<?phpif($a<0):?>
是负数拉
<?phpendif;?>
上面的语句等同于
<?phpif($a<0){?>
是负数拉
<?php}?>
PHP中那些语法有替代语法?
流程控制(包括if,while,forforeach,switch)这几个语句有替代语法。
替代语法的基本形式:
左花括号({)换成冒号(:),把右花括号(})分别换成endif;,endwhile;,endfor;,endforeach;以及endswitch;
while替代语法:
<?phpwhile(expr):?> <li>循环点什么</li> <?phpendwhile;?>
其它替代语法可以类推。
热门推荐
1 狗狗下楼训练
3 狗狗训练头盔
6 狗狗训练机构
7 训练狗狗步骤
9 狗狗能训练
10 狗狗基本动作训练方法
11 怎么训练狗狗叼饭盆
12 狗狗一岁了还能训练吗
13 训练狗狗的
14 宁波狗狗训练
15 训练狗狗拉屎
16 教狗狗训练
17 狗狗要怎么训练上厕所
18 狗狗靠的训练