它们是相同的,但是如果您的代码中包含MVC并且不想在代码中产生大量回声,那么第二个方法就很棒。例如,在我的.phtml
文件(Zend Framework)中,我将编写如下内容:
<?PHP if($this->value): ?>
Hello
<?PHP elseif($this->asd): ?>
Your name is: <?= $this->name ?>
<?PHP else: ?>
You don't have a name.
<?PHP endif; ?>
if(){}和if()之间的区别:endif;
它们是相同的,但是如果您的代码中包含MVC并且不想在代码中产生大量回声,那么第二个方法就很棒。例如,在我的.phtml
文件(Zend Framework)中,我将编写如下内容:
<?PHP if($this->value): ?>
Hello
<?PHP elseif($this->asd): ?>
Your name is: <?= $this->name ?>
<?PHP else: ?>
You don't have a name.
<?PHP endif; ?>