O'Reilly logo

Ubuntu Unleashed 2013 Edition: Covering 12.10 and 13.04, Eighth Edition by Matthew Helmke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Special Operators

The ternary operator and the execution operator work differently from those we have seen so far. The ternary operator is rarely used in PHP, thankfully, because it is really just a condensed conditional statement. Presumably it arose through someone needing to make a code occupy as little space as possible because it certainly does not make PHP code any easier to read.

The ternary operator works like this:

$age_description = ($age < 18) ? "child" : "adult";

Without explanation, that code is essentially meaningless; however, it expands into the following five lines of code:

if ($age < 18) {  $age_description = "child";} else {  $age_description = "adult";}

The ternary operator is so named because it has three operands: a condition ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required