PHP Shorthand if Statements
Short Hand If
To write shorter code, you can write if
statements on one line.
Short Hand If...Else
if
...else
statements can also be written in one line, but the syntax is a bit different.
Example
One-line if
...else
statement:
$a = 13;
$b = $a < 10 ? "Hello" : "Good Bye";
echo $b;
Try it Yourself »
This technique is known as Ternary Operators, or Conditional Expressions.