PHP表示法,如if:endif


PHP notation like if : endif

我已经开始学习一种比标准更喜欢的新PHP表示法

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

相反,它使用

<?php if (...) :
 // code here
endif; ?>

但我不知道如何在上面加上其他的。有人能告诉我怎么做吗?

控制结构的辅助符号为

<?php if (cond): ?>
<?php elseif(cond): ?>
<?php else: ?>
<?php endif; ?>

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

/* 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