Concatenate - comma vs punctuation

Greetings to all,

I am an old guy who have started to learn html, css and php.
Is there any difference using comma vs punctuation when concatenate?
For example:

$number = 5;
$text = “hello”;

echo “Coool string”, " and another string" . " " . $number, 5 * 44;

Both seems to work but all books I have started to read all use punctuation…but why not use comma?

I have honestly never seen a comma used this way and I’m surprised it doesn’t issue any warnings.

It’s not even listed as a string operator:

You should certainly stick with the period. Here is a good link to learn about strings and the various ways to build them:

I also recommend everyone develop a coding standard. I personally use the PEAR standards:

Ah, this does seem to be only related to the echo function so it should never be used IMO.

For example:

$output = “Coool string”, " and another string" . " " , $number, 5 * 44;
echo $output;

This issues “Parse error: syntax error, unexpected ‘,’”

Just for further clarification…

echo doesn’t do any concatenation, so take this for example:

$a = "This is a " . “concatenated” . “string”;
$b = "This is a " . “concatenated” . “string”;
$c = "This is a " . “concatenated” . “string”;

echo $a;
echo $b;
echo $c;

You could instead do

echo $a, $b, $c;

Sponsor our Newsletter | Privacy Policy | Terms of Service