Archives

Articles tagged ‘alternative’

Alternative syntax for PHP control structures

While it’s not a great secret, many people still not aware of the alternative syntax for control structures under PHP.

The C-like syntax for control structures are very intuitive but can deal lots of trouble when your code has lot of pages and lots of ifs, fors, while and therefore lots of opening and closing braces.

NOTE: As remembered by jakyra on DZone, if you keep your code tidy you shouldn’t have functions that long and though not having this kind of problem, but this alternative syntax still have good benefits.

The alternative syntax

The alternative syntax consists in changing the opening brace ({) to a colon (:) and each closing brace to its respective closing function: endif;, endfor;, endforeach;, endwhile; and endswitch;.
Read the full article