DanielMorgan

Web Developer

Sep.25.13

There is a trick used in PHP that I see for “If this, then echo this, else echo that“. This trick uses two short-hand methods of PHP simitaniously to create an easy, extra short-hand version of what can be a sizable logic structure.

First is the PHP shorthand for breaking out of HTML, into PHP, and printing a PHP variable. This normal, or long way of doing this is :

echo $my_variable;

The shorthand version uses the opening tag of “< ?=" , which is shorthand for "< ? echo ..." So the exact same results could be gained from :

< ?= $my_variable ? >

Note there is no need to terminate the string with a semicolon, as no parsable PHP is expected beyond our single expression.

The next shorthand method is the IF/THEN/ELSE. Normal or old PHP would look like :