➤ Ternary operators can be defined as a conditional operator that is reasonable for cutting
the lines of codes in your program while accomplishing comparisons as well as conditionals.
This is treated as an alternative method of implementing if-else or even nested if-else statements.
Syntax:
(Conditional statement) ? (Statement_1) : (Statement_2);
For instance:
$result = 62;
echo $result >= 50 ? "Passed\n" : "Failed\n";
// outputs: Passed
$x = 10;
$y = 20;
$max = $x > $y ? $x : $y;
echo $max."\n";
// outputs: 20
function minvalue($a,$b) {
return $a > $b ? $a : $b;
}
echo minvalue(150,70);
// outputs: 150