An Interest In:
Web News this Week
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
- April 12, 2024
May 29, 2015 12:00 pm
Original Link:
The Ternary Operator in PHP
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,
Original Link:
Share this article:
Tweet
No Article Link
TutsPlus - Code
Tuts+ is a site aimed at web developers and designers offering tutorials and articles on technologies, skills and techniques to improve how you design and build websites.More About this Source Visit TutsPlus - Code