PHP - “萨尔的购物中心是 $emo” VS "Sal's mall is ".$emo - 带引号连接效率的字符串

发布于 2024-09-13 07:19:19 字数 1432 浏览 3 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

木有鱼丸 2024-09-20 07:19:19

不用介意微观优化。选择使您的代码更具可读性的因素。

Never mind micro-optimization. Choose what makes your code more readable.

给不了的爱 2024-09-20 07:19:19
'Sal\'s mall is '.$emo.'.'

第三种方式效率更高(稍微)。
你可以自己做一个循环来测试它:

for ($i = 0; $i < 100000; $i++) {
    // enter code here 
}
'Sal\'s mall is '.$emo.'.'

The third way is more efficient (slightly).
You can test it by yourself doing a loop:

for ($i = 0; $i < 100000; $i++) {
    // enter code here 
}
摇划花蜜的午后 2024-09-20 07:19:19

好吧,当你使用单引号时,PHP 假设它只是一个字符串,但如果你使用双引号,它会解析它以查找内部变量。因此,使用单引号和连接会更有效。无论如何,你必须亲自测试并比较结果。

Well, when you use single quotes, PHP assumes it's just a string, but if you use double quotes, it's gonna parse it to find variables inside. So, using single quotes and concatenation is more efficient. Anyways, you have to test it for yourself and compare the results.

毁虫ゝ 2024-09-20 07:19:19

相信我...如果您不得不问,相对于页面加载的其余部分,速度不会有任何有意义的差异。

Trust me... if you have to ask, there's not going to be any meaningful difference in speed relative to the rest of your page load.

月棠 2024-09-20 07:19:19

没有区别
在询问性能相关问题之前,先了解如何分析您的应用程序。

There is no difference.
Learn to profile your app before asking performance related questions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文