You will find several different methods that people use, and each of them has its own place.
<?php if($first_condition): ?> <?php elseif ($second_condition): ?> <?php else: ?> <?php endif; ?>
If your php.ini attribute has short_open_tag = true (usually it is on line 141 the php.ini file by default), you can replace your open php tag with <?php with <? . This is not recommended , as most real-time slices are disabled (including many CMS such as Drupal, WordPress, and Joomla). I already tested short open tags in Drupal and confirmed that it will break your site, so stick with <?php . short_open_tag is not enabled by default in all server configurations and should not be accepted as such when developing for unknown server configurations. Many hosting companies have disabled short_open_tag .
A quick search for short_open_tag on stackExchange shows 830 results. https://stackoverflow.com/search?q=short_open_tag Many people have problems with something that they simply shouldn't play with.
with some server environments and applications, short open php tags will still break your code, even if short_open_tag set to true .
short_open_tag will be removed in PHP6, so do not use short tags.
all future PHP versions will be discarded short_open_tag
“For several years, it was recommended that you do not use the short tag“ short cut ”and instead use the full tag combination. With the widespread use of XML and the use of these tags in other languages, the server can easily get confused and ultimately parse the wrong code in the wrong context. But since this short slice has been a feature of such a long time, it is still still supported for backward compatibility, but we recommend that you not use them. " - Jelmer Sep 25 '12 at 9:00 php: "short_open_tag = On" does not work
and
Usually you write PHP as follows :. However, if enable_short_tags, you can use :. Sort tags also provide additional syntax: which is equal.
Short tags may seem cool, but they aren’t. They cause only more problems. Oh ... and IIRC they will be removed from PHP6. Krozin answered on August 24 10 at 22:12 Problem with php short_open_tag
and
To answer the question why I am quoting Zend PHP 5: "Short tags were for some time the standard in the PHP world, however, they have the main drawback of the inconsistency with the XML headers and, therefore, are somewhat marginalized." - Fluffy Apr 13 '11 at 14:40 Are short tags suitable for PHP?
You can also see how people use the following example:
<?php if($first_condition){ ?> <?php }else if ($second_condition){ ?> <?php }else{ ?> <?php } ?>
This will work, but it is highly deprecated because it is not considered legible and is not what you would use this format for. If you had a PHP file in which you had a block of PHP code in which there were no inline tags inside, you should use the bracket format.
The following example shows when to use the bracket method
<?php if($first_condition){ /*$first_condition is true*/ }else if ($second_condition){ /*$first_condition is false and $second_condition is true*/ }else{ /*$first_condition and $second_condition are false*/ } ?>
If you do this code for yourself, you can do what you like, but if you work with a team at work, it is recommended that you use the correct format for the right circumstance. If you use brackets in the built-in html / php scripts, this is a good way to fire, since no one will want to clear your code after you. IT executives will take care of the legibility of the code and the degree of college professor in readability.
UPDATE
based on duskwuff's comments, it's still unclear if shorthand is not recommended (by php standards) or not. I will update this answer when I receive more information. But based on many documents found on the Internet about reducing the harm to portability. Anyway, I personally will not use it, since it does not give advantages, and you should rely on a setting that is not enabled for each web host.