php 里的 if(): endif; 类似写法具体有何好处?

WBOY
Release: 2016-06-06 20:44:10
Original
1990 people have browsed it

<code class="lang-php"><?php if(!isset($a)):
    xxx;
endif;
</code></code>
Copy after login
Copy after login

回复内容:

<code class="lang-php"><?php if(!isset($a)):
    xxx;
endif;
</code></code>
Copy after login
Copy after login

主要是在 HTML 模板里用这种写法比较清晰,尤其当配合 short_open_tag 时。

<code class="lang-php"> if(isset($a)): ?>
    if($a): ?>
       <span>variable a is exist and not empty</span>
    endif; ?>
 endif; ?>
</code>
Copy after login

作为对比,要比下面的写法好看一点,尤其是当逻辑复杂的时候,很可能分不清花括号。

<code class="lang-php"> if(isset($a)) { ?>
    if($a) { ?>
       <span>variable a is exist and not empty</span>
    } ?>
 } ?>
</code>
Copy after login

http://php.net/manual/zh/control-structures.alternative-syntax.php
http://php.net/manual/zh/ini.core.php#ini.short-open-tag

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template