PHP Control Structures Alternative syntax for control structures


PHP provides an alternative syntax for some control structures: if, while, for, foreach, and switch.

When compared to the normal syntax, the difference is, that the opening brace is replaced by a colon (:) and the closing brace is replaced by endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively. For individual examples, see the topic on alternative syntax for control structures.

if ($a == 42):
    echo "The answer to life, the universe and everything is 42.";

Multiple elseif statements using short-syntax:

if ($a == 5):
    echo "a equals 5";
elseif ($a == 6):
    echo "a equals 6";
    echo "a is neither 5 nor 6";

PHP Manual - Control Structures - Alternative Syntax