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打开和关闭标签


基础教程推荐
- 超薄框架REST服务两次获得输出 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01