Reply to Re: string concat vs. join/implode

Your name:

Reply:


Posted by gosha bine on 05/14/07 20:35

NoWhereMan wrote:
> Maybe a stupid question.
>
>
> -------------------------
> 1
> -------------------------
> $str = '';
>
> for($i=0; $i<10; $i++)
> $str .= $i;
>
> echo $str;
>
> -------------------------
> 2
> -------------------------
> $str = array();
>
> for($i=0; $i<10; $i++)
> $str[]= $i;
>
> echo implode('', $str);
>
> -------------------------
>
> I suppose the latter will be more performant because there's less work for
> the garbage collector, am I right?
>
> thanks
>

I think performance differences are hardly noticeable here, but the
latter method is still far better. In real life we use non-empty
separators and mostly omit the last one: "a" + "b" + "c" -> "a,b,c".
implode() does exactly this, with concatenation we will need some ugly
cleanup at the end of the loop.


--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация