$x == 1 ? print "x was '1'" : print "x was something else";
While that's technically correct it doesn't take advantage of the fact that the ternary operator has a return value; whatever expression is evaluate after the ?.
See another adaptation that takes advantage of this feature.
print( "x was " . $x == 1 ? "'1'" : "someting else" );
Dave
In reply to Re^2: "x ? y : z" notation
by davido
in thread "x ? y : z" notation
by apok
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |