为什么回波比打印更快?

编程入门 行业动态 更新时间:2024-10-15 20:21:31
本文介绍了为什么回波比打印更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在 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.

更多推荐

为什么回波比打印更快?

本文发布于:2023-05-29 03:33:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/335812.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:回波   更快

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!