I noticed that you can do concatenation as a dot, and a comma. But what is the difference between these two operators?
1 answer
There is no concatenation separated by a comma in php. What you think of as php.net/manual/ru/function.echo.php for Russian-language documentation is actually the result of translation difficulties. First, notice how the example of using this function is shown:
void echo ( string $arg1 [, string $... ] ) It clearly shows that the comma acts as a delimiter of arguments.
Secondly, the following is written in the original :
It is not really a need to use parentheses with it . It can not always be used. Additionally, you must not be enclosed within parentheses .
And the translation is this:
In fact, echo is not a function, but a language construct, so it is not necessary to enclose the arguments in brackets . echo (unlike other language constructs) does not behave as a function, therefore it can not always be used in the context of a function. In addition, if you want to pass more than one argument to echo, these arguments cannot be enclosed in brackets .
In my opinion, in the original it is more clear that brackets can be used only if one argument is passed to echo , and in other cases the arguments are passed without brackets separated by commas, which will be the separator of these arguments, and not the concatenation operator.
As a result, you can try to display with the help of this function several variables of different data types and compare what you see with the output result using concatenation.
echo "test " . true . 1; echo "test " , true , 1;
echo, you will immediately understand the difference ... - Akina