When to use alternative syntax
Please, please use alternative syntax when mixing HTML & PHP.
This is ugly:
<?php if( some_function() ) { ?>
Lorem ipsum
<?php } else { ?>
<?php foreach( $some_array as $foo ) {
Dolar sit amet
<?php } ?>
Consectetur adipisicing
<?php } ?>
Most IDE's will not highlight the braces when mixing and this is really not clear.
Better solution:
<?php if( some_function() ):?>
Lorem ipsum
<?php else:?>
<?php foreach( $some_array as $foo ):?>
Dolar sit amet
<?php endforeach;?>
Consectetur adipisicing
<?php endif;?> Written by Ekrem Büyükkaya
Related protips
1 Response
the "endif" keyword makes me shutter in remembrance of my vb days.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Did you know?
PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#