Wednesday, May 22, 2013

Ternary Operators (?:)


What Does Ternary Logic Look Like?

/* most basic usage */
$var = 5;
$var_is_greater_than_two = ($var > 2 ? true : false); // returns true

What Are The Advantages of Ternary Logic?
There are some valuable advantages to using this type of logic:
  • Makes coding simple if/else logic quicker
  • You can do your if/else logic inline with output instead of breaking your output building for if/else statements
  • Makes code shorter
  • Makes maintaining code quicker, easier

No comments:

Post a Comment