Difference between period and comma when concatenating with echo versus return?

I just found that this will work:

echo $value , " contiue";

but this does not:

return $value , " contiue";

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.


the . is the concatenation operator in PHP, for putting two strings together. The comma can be used for multiple inputs to echo.


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

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.

{Source}

链接地址: http://www.djcxy.com/p/1834.html

上一篇: 什么是。 (点)在PHP中做?

下一篇: 与echo和return连接时的句号和逗号之间的区别?