开发者

What's the fastest way of concatenating strings in PHP?

I want to combine two variables together:

$var1 = 'Welcome ';

$var2 = $_SESSION['UserName'];

Which of these will work faster? Code sample 1:

$var3 = $var1.$var2;

Or code sample 2:

$var3 = "$v开发者_开发问答ar1$var2";


Code sample 1 won't work at all..

Syntax considerations set aside, Sample 1 should be trivially faster because it doesn't involve parsing a string (looking for variables).

But it's very, very trivial..


Both examples would provide the same result - $var3 equal to "Welcome Wazzy". However, Code Sample 1 will work significantly faster. Try it out with large sets of data (or via concatenating small sets a million times or so), and you will see that concatenation works significantly faster than variable substitution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜