您所在的位置: 首页 > 技术文档 > 网络编程

PHP中判断、循环的几种写法

文章来源:梦之都 更新日期:2009-11-02  我要评论(0)  欢迎投稿
  1. 摘要:PHP中,有关判断、循环等几种写法......
  2. 标签:PHP If While 循环

  3. 上一篇: / 下一篇: / 教程列表

下面介绍几种PHP中判断、循环的几种写法

最普通的判断:

<?php
if( $args != NULL )
{
        call_func($args);
}
?>

对于单行的执行语句,可以写成:

<?php
if( $args != NULL ) call_func($args);
?>

也可以使用引号的方式。

<?php
if( $args != NULL ):
        call_func($args);
endif;
?>

这中写法通常运用于判断中包含许多HTML标签,或 PHP 的断开,如:

<?php
<?php if( $args! =NULL ): ?>
        <p>Args exists</p>
<?php else: ?>
        <p>Args NOT exists</p>
<?php endif; ?>
?>

同理,While也可以这么写:

<?php
while( $run ):
        call_func();
endwhile;
?>

学过Python的朋友会发现,这种写法其实和Python很相似,用缩进替换了大括号。

XHTML   CSS   JavaScript   HTML视频  

JavaScript语言精粹

作者:Douglas Crockford 本书的作者Douglas Crockford是JavaScript开发社区最知名的权威,JavaScript的发明人Brendan Eich说他是“Yoda of lambda programming...