Solutions Log

So I only have to figure things out once.

Ternary Operator

Like this:

$variable = condition ? if true : if false

Get it?

if ($cake == "fresh") {
    print "Yum yum! This cake is tasty.";
} else {
    print "Yuck! This cake tastes awful!";
}

// This can be rewritten as the following ternary statement:

$message = ($cake == "fresh") ? "Yum yum! This cake is tasty." : "Yuck! This cake tastes awful!";

Sources

If/Then/Else statments are a type of Control Structure: Wikipedia, PHP docs.

Comments