简体   繁体   English

PHP表示法,如if:endif

[英]PHP notation like if : endif

I've started to learn a new PHP notation I like better than the standard 我已经开始学习比标准更好的新PHP表示法

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

Instead, it uses 相反,它使用

<?php if (...) :

 // code here

endif; ?>

But I can't figure out how to put an else on that. 但是我不知道该如何处理。 Can someone tell me how to do that? 有人可以告诉我该怎么做吗?

The secondary notation for control structures goes 控制结构的次要符号

<?php if (cond): ?>

<?php elseif(cond): ?>

<?php else: ?>

<?php endif; ?>

You should only be using this notation when templating HTML, as blocks and indentation make code much more readable and easier to follow. 仅在模板化HTML时才应使用此表示法,因为块和缩进可使代码更易读且易于遵循。 Some programmers will argue that the bracketless notation should never be used. 一些程序员会争辩说永远不要使用无括号表示法。

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

as from http://php.net/manual/en/control-structures.elseif.php http://php.net/manual/en/control-structures.elseif.php开始

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM