The terniary operator is great; as its name implies it takes three arguments. Like an "if" it takes an expression to evaluate to true or false; then comes the ?. If the first evaluation is true, the first expression after the ? is used. Then comes the : which is what is used if the first evaluation is false. So you can read it "Is this true? yes - do this : no - do this; ".
Basically, it gets the same results as a simple if...else block. I think it’s faster and more efficient, though.
$result = $something ? $this : $that;
if($something) {
$result = $this;
} else {
$result = $that;
}
We use the .= assignment operator a lot in snippets:
// we got a list of stuff, maybe from the database, here's how to display it:
$output = "<ul>"; // start the list
foreach ($list as $item) {
$output .= "<li>$item</li>"; // add an li for each item in the list
}
$output .= "</ul>"; // add the list closing tags
return $output;