PHP alternative to Brackets

RHochstenbach

Administrator
If you have a lot of IF statements and loops nested into each other, you might find it confusing to see which bracket belongs to which instruction. Something like this:
PHP:
if(1 == 1) {
while(1 == 1) {
echo "1";
if(2==2) {
while(2==2) {
echo "2";
}
}
}
}

You can replace the bracket with the word end, followed by the name of the instruction. Examples are endif, endwhile, endfor etc. This gives a result similar to this:

PHP:
if(1 == 1) {
while(1 == 1) {
echo "1";
if(2==2) {
while(2==2) {
echo "2";
endwhile;
endif;
endwhile;
endif;

Looks easier to read, doesn't it :)
 
I'd recommend using the alternative syntax only when working with templates, otherwise use the normal opening/closing brackets.
 
I'd recommend using the alternative syntax only when working with templates, otherwise use the normal opening/closing brackets.
It's always the best way using the 'official' method with brackets, because these are more compatible with the PHP versions.
 
Back
Top