$top += $i ? 12 : 0;
If $i is
- set
- and not
false - and not
null
increment $top by twelve; otherwise, by zero, implicitly turning $top (not $i) into a numeric variable if it isn't one already.
If $i has a value set (not empty/null meaning condition resolves to true), then 12 is added to $top and 0 otherwise.
It is basically shorthand of:
if ($i)
{
$top += 12;
}
else
{
$top += 0;
}
If $i is true (e.g., not zero or an empty string), 12 is added to $top. Otherwise, nothing is added to $top.
This is equivalent to
if($i)
$top = top + 12;
Increase value of $top by 12 if $i has true boolean value (ie. $i = 1, $i = true etc.) or by 0 if not.
http://www.php.net/manual/en/language.operators.assignment.php
The $i ? 12 : 0 is a "shorthand" if statement. In this case, $i is evaluated as an expression. If the expression evaluates to true, then the value 12 is used as the r-value in the addition-assignment expression. If $i evaluates to false, then 0 is used as the r-value.