PHP Knowledge Base
The Ternary Operator
Example of Standard if/then/else
Conditional Statement
if( $valid ) { $x = 'yes'; } else { $x = 'no'; }
Above Example Written Using the Ternary Operator
$x = $valid ? 'yes' : 'no';
Ternary Shorthand (PHP 5.3+)
Example of Standard if/then
Conditional Statement
if( !$start ) { $start = 1; }
Above Example Written Using Ternary Shorthand
$start = $start ?: 1;
NULL