What is the fastest way to concatenate strings in PHP?

I want to combine two variables together:

$var1 = 'Welcome ';

$var2 = $_SESSION['UserName'];

Which ones will work faster? Code Example 1:

$var3 = $var1.$var2;

Or sample code 2:

$var3 = "$var1$var2";
+3
source share
2 answers

Sample code 1 will not work at all.

Given syntax examples, example 1 should be trivially faster because it does not include parsing a string (searching for variables).

But it is very, very trivial.

+7
source

- $var3, "Welcome Wazzy". 1 . ( ), , , .

+2

Source: https://habr.com/ru/post/1763599/


All Articles