php echo vs openamp;close tag(php echo vs打开和关闭标签)
问题描述
澄清一下:回显与打印"和双引号与单引号"的问题已经完全理解,这是关于另一件事:
Just to clarify: The issues "echo vs print" and "double quotes vs single quotes" are perfectly understood, this is about another thing:
有什么理由会让人更喜欢:
Are there any reasons why one would prefer:
echo '<table>';
foreach($lotsofrows as $row)
{
echo '<tr><td>',$row['id'],'</td></tr>';
}
echo '<table>';
结束:
<table><?php
foreach($lotsofrows as $row)
{ ?>
<tr>
<td><?php echo $row['id']; ?></td>
</tr><?php
} ?>
</table>
其中一个执行/解析会更快吗?更优雅?(等等)
would either one execute/parse faster? is more elegant? (etc.)
我倾向于使用第二个选项,但我担心我可能会忽略一些明显/必要的内容.
I tend to use the second option, but I'm worried I might be overlooking something obvious/essential.
推荐答案
我同意 Peter Bailey 的观点.但是,在视图中,我使用语句的替代语法,并且更喜欢短标签(尤其是回显).所以上面的例子改为:
I agree with Peter Bailey. However, in views I use the alternative syntax for statements, and much prefer short tags (particularly for echoing). So the above example would instead read:
<table>
<? foreach($lotsofrows as $row): ?>
<tr>
<td><?= $row['id']; ?></td>
</tr>
<? endforeach; ?>
</table>
我相信这是 Zend Framework 的首选标准.
I believe this is the preferred standard for Zend Framework.
这篇关于php echo vs打开和关闭标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:php echo vs打开和关闭标签
基础教程推荐
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
