在 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.
更多推荐
为什么回波比打印更快?
发布评论