Suppose you wanted to test a condition like so:
if(bla) then
print A
else
print B
end if
Pretty basic stuff. But how many lines is that? Further more, imagine if you had to do this 100 times. I am sure your head is reeling at that thought right now. So is there a better and efficient way? I would say yes. The solution would be the ternary operator. With this operator, code like so:
<?php
if(bla) {
?>
print A
<?php
} else {
?>
print B
<?php
}
?>
could easily be rewritten as:
<?php echo (bla ? "A" : "B"); ?>
Of course, this is an over-simplified piece of code but hopefully, you get the point. For example, I use this all the time to determine what parts of my navigation menus to highlight on a given page, based on the URI.
Now, isn't that much easier?

Did you find this useful? Letz LEARN something! There are 15 other short and easy lessons I have compiled into an Ebook. You can email me at yawatide at yahoo dot com for details on how to obtain your copy.
Thanks