php shorthand ternary code example
Example 1: php ternary operator
(Condition) ? (Statement1) : (Statement2);
Example 2: php ternary operator
<?php
(if Condition) ? (stat1) : (stat2);
$var1 = 5;
$var2 = 2;
echo $check = ($var1 > $var2) ? "right" : "wrong";
?>
Example 3: php ternary
$result = $condition ? 'foo' : 'bar';
Example 4: php ternary operators
$result = $condition ? 'foo' : 'bar';
if ($condition) {
$result = 'foo'
} else {
$result = 'bar'
}
Example 5: php ternary shorthand
$y = $x ? "true" : "false";