Verification: a143cc29221c9be0

Php and with no shortcut

if shortcut – no braces

If your if statement has only one directive, like the following:

if ($x) { echo “This directive”; }

You can drop the braces:

if ($x) echo “This directive”;

if-else shortcut

You’re probably used to the long, formal version of the if-else statement in PHP:

if ($x == 5) { $y = 3 } else { $y = 2 }

While there is nothing wrong with this statement, it’s more efficient to use the shortened version, using the ternary operator:

($x == 5) ? $y = 3 : $y = 2;