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?
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?
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:
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
echo
is a language construct (not a function) and can take multiple arguments, that's why,
works. using comma will be slightly even (but only some nanoseconds, nothing to worry about).
is the concatenation operator (the glue) for stringsDot (
.
) is for concatenation of a variable or string. This is why it works when you echo while concatenating two string and it works when you return a concatenation of a string in a method. But the comma doesn't concatenate and this is why the return statement won't work.echo
is a language construct that can take multiple expressions which is why the comma works:Use the dot for concatenation
the
.
is the concatenation operator in PHP, for putting two strings together. The comma can be used for multiple inputs to echo.echo
is actually a function (not really but let's say it is for argument) that takes any number of parameters and will concatenate them together.While
return
is not a function, but rather a keyword, that tells the function to return the value, and it is trying to interpret,
as some kind of operator. You should be using.
as the concatenation operator in the case when you are using the return statement.return
does only allow one single expression. Butecho
allows a list of expressions where each expression is separated by a comma. But note that sinceecho
is not a function but a special language construct, wrapping the expression list in parenthesis is illegal.