<?php
if(!isset($a)):
xxx;
endif;
主要是在 HTML 模板里用这种写法比较清晰,尤其当配合 short_open_tag 时。
<? if(isset($a)): ?>
<? if($a): ?>
<span>variable a is exist and not empty</span>
<? endif; ?>
<? endif; ?>
作为对比,要比下面的写法好看一点,尤其是当逻辑复杂的时候,很可能分不清花括号。
<? if(isset($a)) { ?>
<? if($a) { ?>
<span>variable a is exist and not empty</span>
<? } ?>
<? } ?>
http://php.net/manual/zh/control-structures.alternative-syntax.php
http://php.net/manual/zh/ini.core.php#ini.short-open-tag