if(){}和if()之间的区别:endif;

if(){}和if()之间的区别:endif;

问题描述:

...之间是否有任何区别

Are there any differences between...

if ($value) {

}

...和...

if ($value):

endif;

?

它们是相同的,但是如果您的代码中包含MVC并且不想在代码中产生大量回声,那么第二个方法就很棒.例如,在我的.phtml文件(Zend Framework)中,我将编写如下内容:

They are the same but the second one is great if you have MVC in your code and don't want to have a lot of echos in your code. For example, in my .phtml files (Zend Framework) I will write something like this:

<?php if($this->value): ?>
Hello
<?php elseif($this->asd): ?>
Your name is: <?= $this->name ?>
<?php else: ?>
You don't have a name.
<?php endif; ?>