PHP variable interpolation vs concatenation

PhpStringVariablesConcatenationString Interpolation

Php Problem Overview


What is the difference between the two following methods (performance, readability, etc.) and what do you prefer?

echo "Welcome {$name}s!"

vs.

echo "Welcome " . $name . "!";

Php Solutions


Solution 1 - Php

Whatever works best for you works... But if you want to go for speed use this:

echo 'Welcome ', $name, '!';

The single quotes tell PHP that no interpretation is needed, and the comma tells PHP to just echo the string, no concatenation needed.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAleyView Question on Stackoverflow
Solution 1 - PhpBornietView Answer on Stackoverflow