问题描述
澄清一下:回显与打印"和双引号与单引号"的问题已经完全理解,这是关于另一件事:
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打开和关闭标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!