|
|
Tutorials » Php »
|
Topic |
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.
|
|
A Note |
Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial.
Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.
|
|
|
|