php echo vs open& close标签 [英] php echo vs open&close tag
问题描述
仅需澄清一下:回声vs打印"和双引号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 open& close标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!