Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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 = "$var1$var2";
like image 590
Wazy Avatar asked Dec 07 '25 09:12

Wazy


1 Answers

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..

like image 179
Berzemus Avatar answered Dec 08 '25 22:12

Berzemus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!