PHP if statement in shorthand

Another “tired of hunting for the exact syntax” things… Here’s shorthand for an “if” statement:

echo isset($var) ? $var : "sorry, nothing here";

One Response to “PHP if statement in shorthand”

  1. Sunny Says:

    Also called a ternary operator. The outer parentheses can be dropped, too.

Leave a Reply

Subscribe without commenting