+ 1

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

i was going through a word press code and i saw if (): endif;. what is the difference with the conditional we learned here and when is it better to use one over the other?

17th Dec 2018, 5:31 AM
Zakariya Abubakar
Zakariya Abubakar - avatar
1 Odpowiedź
+ 7
It's an alternative syntax, this alternative syntaxes can be used for these statements: if ... endif while ... endwhile for ... endfor foreach ... endforeach switch ... endswitch Reference: http://php.net/manual/en/control-structures.alternative-syntax.php It seems they are just the same, none was "better" than another, people have different preference for which to use and when, but in general, these alternatives are "supposedly" provide clearer readability, especially when the code involves a lot of mix-ups of PHP and HTML. In the end it all comes back to one's preference, some find it clearer with braces, others do prefer the alternatives. An external discussion over which and when to choose: https://stackoverflow.com/questions/564130/difference-between-if-and-if-endif Hth, cmiiw
17th Dec 2018, 6:43 AM
Ipang