为什么回波比打印更快? [英] Why is echo faster than print?

查看:129
本文介绍了为什么回波比打印更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP 中,为什么是 echo print



他们做同样的事情...为什么一个比另一个更快?

$他们是否 完全 同样的事情?

解决方案

echo print 实际上两者之间(差不多)的区别是 print 将返回整数 1 ,而 echo 不返回任何内容。请记住,这两个都不是一个函数,而是语言结构。 echo 允许您在使用它时传递多个字符串,就像它是一个函数(例如 echo($ var1,$ var2,$ var3) / code>)。



echo 也可以使用语法<?= $ var1; ?> (代替<?php echo $ var1;?> )。



至于哪个更快,有很多在线资源试图回答这个问题。 PHP Benchmark 的结论是,现实中,回波和打印函数服务于确切的目的,因此在一个小的事情要注意的是,当使用逗号分隔项目,而使用echo函数,项目运行稍快。



它将真正落到你的偏好,因为速度的差异(无论他们实际上是什么)是微不足道的。


In PHP, why is echo faster than print?

They do the same thing... Why is one faster than the other?

Do they do exactly the same thing?

解决方案

echo and print are virtually (not technically) the same thing. The (pretty much only) difference between the two is that print will return the integer 1, whereas echo returns nothing. Keep in mind that neither is actually a function, but rather language constructs. echo allows you to pass multiple strings when using it as if it were a function (e.g., echo($var1, $var2, $var3)).

echo can also be shorthanded by using the syntax <?= $var1; ?> (in place of <?php echo $var1; ?>).

As far as which is faster, there are many online resources that attempt to answer that question. PHP Benchmark concludes that "[i]n reality the echo and print functions serve the exact purpose and therefore in the backend the exact same code applies. The one small thing to notice is that when using a comma to separate items whilst using the echo function, items run slightly faster."

It will really come down to your preference, since the differences in speed (whatever they actually are) are negligible.

这篇关于为什么回波比打印更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆