Skip to content


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

 

Are there any differences between…

if ($value) {

}

…and…

if ($value):

endif;

?

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:

ANSWER:

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

Posted in Php. Tagged with , .

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

You must be logged in to post a comment.