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

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

This site uses Akismet to reduce spam. Learn how your comment data is processed.