PHP表示法如if:endif

时间:2011-10-10 21:40:47

标签: php

我开始学习一种新的PHP符号,我比标准

更好
<?php if (...) 
{
    // code here
} ?>

相反,它使用

<?php if (...) :

 // code here

endif; ?>

但我无法弄清楚如何把别的东西放在那上面。有人可以告诉我该怎么做吗?

2 个答案:

答案 0 :(得分:3)

control structures的辅助表示法

<?php if (cond): ?>

<?php elseif(cond): ?>

<?php else: ?>

<?php endif; ?>

在模板化HTML时,您应该只使用这种表示法,因为块和缩进使代码更易读,更容易理解。一些程序员会争辩说,无括号的符号应该从不使用。

答案 1 :(得分:0)

/* Correct Method: */
if($a > $b):
    echo $a." is greater than ".$b;
elseif($a == $b): // Note the combination of the words.
    echo $a." equals ".$b;
else:
    echo $a." is neither greater than or equal to ".$b;
endif;

来自http://php.net/manual/en/control-structures.elseif.php