Control Structures

Ternary Operators

$var = 5;
$var_is_greater_than_two = ($var > 2 ? true : false); // returns true.

Alt Syntax (for views)

PHP offers an alternative syntax for some of its control structures; namely, if, while, for, foreach, and switch. In each case, the basic form of the alternate syntax is to change the opening brace to a colon : and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively.

<?php if ($x == 1): ?>
    ...
<?php else: ?>
    ...
<?php endif; ?>