xxxxxxxxxx
// Both ternary and if/else returns the same result
// ternary
$result = $condition ? 'foo' : 'bar';
// if/else
if ($condition) {
$result = 'foo'
} else {
$result = 'bar'
}
xxxxxxxxxx
(conditional) ? (execute this when true) : (execute this when false);
# example
<?php
$age = 20;
print ($age >= 18) ? "Adult" : "Not Adult";
?>
# output
Adult
xxxxxxxxxx
<?php echo ($item->name == 'Pizza' || $item->name == 'Pasta')? 'per day' :'Dishes';?>
<?php echo ($section1['line_block']) ? 'width:'. $line_block_percentage. '% ; background-color: #BD9B46;' : 'width:55% ; background-color: red;'; ?>