Expressions: Ternary Operations
Ternary Operator
The ternary operator can be used to conditionally evaluate an expression using the ?
operator, followed by the expression to evaluate if the condition is true, followed by the :
operator, followed by the expression to evaluate if the condition is false.
$foo = $bar ? $bar : $baz;
Short Ternary Operator
The short ternary operator can be used to conditionally evaluate an expression using the ?:
operator, followed by the expression to evaluate if the condition is false.
$foo = $bar ?: $baz;