I have a variable that is being defined as
$var .= "value";
How does the use of the dot equal function?
It's the concatenating assignment operator. It works similarly to:
$var = $var . "value";
$x .=
differs from $x = $x .
in that the former is in-place, but the latter re-assigns $x
.
This is for concatenation
$var = "test";
$var .= "value";
echo $var; // this will give you testvalue
the ".
" operator is the string concatenation operator. and ".=
" will concatenate strings.
Example:
$var = 1;
$var .= 20;
This is same as:
$var = 1 . 20;
the ".=
" operator is a string operator, it first converts the values to strings; and since ".
" means concatenate / append, the result is the string "120
".
In fact when we check the variable with:
var_dump($var);
The result will be:
string(202) "120"
i.e. the content of the variable will be changed to 120!
Not 1 or 20!
来源:https://stackoverflow.com/questions/14846570/what-does-the-operator-mean-in-php