php echo vs打开和关闭标签

php echo vs openamp;close tag(php echo vs打开和关闭标签)
本文介绍了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打开和关闭标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)