控制结构的替代语法
PHP 为某些控制结构提供了另一种语法:if,while,for,foreach 和 switch。
与普通语法相比,不同之处在于,开括号由冒号(:)代替,而右括号分别由 endif;,endwhile;,endfor;,endforeach; 或 endswitch; 代替。有关各个示例,请参阅有关控制结构的备用语法的主题。
if ($a == 42):
echo "The answer to life, the universe and everything is 42.";
endif;
使用短语法的多个 elseif 语句:
if ($a == 5):
echo "a equals 5";
elseif ($a == 6):
echo "a equals 6";
else:
echo "a is neither 5 nor 6";
endif;