PHP Ternary Operator
What are the Ternary Operators?
Explanation
Ternary Operator
Ternary operator is another conditional operator.
Syntax
(expr1) ? (expr2) : (expr3)
In the above syntax the expr1 is a condition when satisfied or true it evaluates expr2, otherwise expr3.
Example :
<?php
$mark = 50;
$result = ($mark>=60)? "Passed Exam":"Failed in Exam";
print "$result";
?>
Result :
Failed in Exam
In the above example, marks of a student is checked in an expression, since its false the value "Failed in Exam" is displayed, if true the first value might be printed.