Home > Backend Development > PHP Tutorial > php 里的 if(): endif; 类似写法具体有何好处?

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:44:10
Original
2032 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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template