From The Video
The ternary operator allows us to simplify some PHP conditional statements. We'll see how it can be used, with test-driven development and refactoring, to simplify code like:
<?php $result = null; if (5>3) { $result = "Bigger"; } else { $result = "Less"; }
Written using a ternary operator, we can write the above comparison as:
<?php $result = 5 > 3 ? "Bigger" : "Less";
This is obviously a much simpler way to write relatively easy to understand conditional statements and something we should consider when writing future code,
Comments