(Condition) ? (Statement1) : (Statement2);
$result = $condition ? 'foo' : 'bar';
// Both ternary and if/else returns the same result
// ternary
$result = $condition ? 'foo' : 'bar';
// if/else
if ($condition) {
$result = 'foo'
} else {
$result = 'bar'
}
$y = $x ? "true" : "false";
(conditional) ? (execute this when true) : (execute this when false);
# example
<?php
$age = 20;
print ($age >= 18) ? "Adult" : "Not Adult";
?>
# output
Adult