Difference between period and comma when concatenating with echo versus return?
I just found that this will work:
echo $value , " continue";
but this does not:
return $value , " continue";
While "." works in both.
What is the difference between a period and a comma here?
return
does only allow one single expression. But echo
allows a list of expressions where each expression is separated by a comma. But note that since echo
is not a function but a special language construct, wrapping the expression list in parenthesis is illegal.
You also have to note that echo
as a construct is faster with commas than it is with dots.
So if you join a character 4 million times this is what you get:
echo $str1, $str2, $str3;
About 2.08 seconds
echo $str1 . $str2 . $str3;
About 3.48 seconds
It almost takes half the time as you can see above.
This is because PHP with dots joins the string first and then outputs them, while with commas just prints them out one after the other.
We are talking about fractions, but still.
Original Source