Home  »  Solutions  »  What I've Learned  »  Ternary Operator in PHP (and javascript)

Ternary Operator in PHP (and javascript)

Nate Weiner - Posted in What I've Learned, , , , Comments (0)
$ternary = ‘Awesome’;
print ‘Does Ternany Rock? ‘;
print ( ($ternany == ‘Awesome’)?(’Yea it sure does.’):(’No.’) );Outputs: Does Ternany Rock? Yea it sure does.

It’s a much more lightweight way of writing a simple if-statement with two outputs.

Where I learned about it:
http://blog.rightbrainnetworks.com/2006/09/18/10-things-you-probably-didnt-know-about-php/

Comments


Leave a Reply