PHP:许多的邻接或者一个破灭? [英] PHP: many concats or one implode?

查看:107
本文介绍了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 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天全站免登陆