Difference between if () { } and if () : endif;

alex picture alex · Feb 19, 2009 · Viewed 210.1k times · Source

Are there any differences between...

if ($value) {

}

...and...

if ($value):

endif;

?

Answer

Thomaschaaf picture Thomaschaaf · Feb 19, 2009

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; ?>