php shorthand code example
Example 1: php shorthand if
$is_admin = ($user['permissions'] == 'admin') ? true : false;
Example 2: php ternary
$result = $condition ? 'foo' : 'bar';
Example 3: php ternary operators
// Both ternary and if/else returns the same result
// ternary
$result = $condition ? 'foo' : 'bar';
// if/else
if ($condition) {
$result = 'foo'
} else {
$result = 'bar'
}
Example 4: php ternary shorthand
$y = $x ? "true" : "false";
Example 5: php if short form
<?php echo ($qte > 0) ? $qte : 0; ?>