Entry
What is a ternary expression?
What is this ? : syntax?
Jun 16th, 1999 07:00
Nathan Wallace, Rasmus Lerdorf, Chad, Egon Schmid
A ternary expression is a shortened form of an if statement:
( (condition) ? "true" : "false" )
If the condition is true, then the above line evaluates to "true" and
if the condition is false, it evaluates to "false".
Another way to look at it. Take this very normal example:
if ($a==1) {
print "a is one";
}
else {
print "a is not one";
}
Even your grandmother could probably tell you what this did. You can
rewrite this with a conditional to confuse your grandmother, like this:
print ( ($a==1) ? "a is one" : "a is not one" );
http://www.php.net/manual/expressions.php3