PHP:许多连接还是一个内爆? [英] PHP: many concats or one implode?

查看:26
本文介绍了PHP:许多连接还是一个内爆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我当前的项目中,我将一个字符串组合成许多小字符串(直接输出不是一种选择).进行多次字符串连接会更有效吗?或者我应该将零件添加到数组中并使其内爆?

In my current project I assemble one string out to many small strings (direct output is NOT an option). Would it be more efficient to do many string concatenations? or should I add the parts to an array and implode it?

推荐答案

首先附注 - 在实际生产应用程序中,任何这些都无关紧要,因为时间差异是表面的,应用程序的优化应该在其他地方(处理网络、数据库、文件系统等).话虽如此,出于好奇:

First a side note - any of this does not matter in a real production application, as the time differences are superficial and the optimization of the application should be done in other places (dealing with network, database, filesystem, etc.). That being said, for curiosity's sake:

implode 可能是更有效的串联,但前提是您已经拥有数组.如果不这样做,它可能会更慢,因为所有增益都会被创建数组和分配其元素所需的时间所抵消.所以保持简单:)

implode may be more efficient concatenation, but only if you already have the array. If you don't, it probably would be slower since all the gain would be offset by the time needed to create the array and allocate its elements. So keep it simple :)

这篇关于PHP:许多连接还是一个内爆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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