String concatenation in PHP

This can be done many ways in PHP. I’m here going to show my two preferred ways:

My personal favorite:

echo string1, string2, string3

Example:

$score = 5;
echo "You scored ", $score, " points!";

Will print:

You scored 5 points!

Using print and dot syntax:

print string1.string2.string3

Example:

$score = 7;
print "You scored ".$score." points!";

Will print:

You scored 7 points!

I try to use the first syntax as much as possible because I believe that it is easier to read in code. Trying to keep it simple

Comments are closed.