下面介绍几种PHP中判断、循环的几种写法。
最普通的判断:
<?phpif($args!=NULL){call_func($args);}?>
对于单行的执行语句,可以写成:
<?phpif($args!=NULL)call_func($args);?>
也可以使用引号的方式。
<?phpif($args!=NULL):call_func($args);endif;?>
这中写法通常运用于判断中包含许多HTML标签,或 PHP 的断开,如:
<?php<?phpif($args! =NULL):?><p>Args exists</p><?phpelse:?><p>Args NOT exists</p><?phpendif;?>?>
同理,While也可以这么写:
<?phpwhile($run):call_func();endwhile;?>
学过Python的朋友会发现,这种写法其实和Python很相似,用缩进替换了大括号。
作者:Douglas Crockford 本书的作者Douglas Crockford是JavaScript开发社区最知名的权威,JavaScript的发明人Brendan Eich说他是“Yoda of lambda programming...