Your question is about the operator .=
. It is a shorthand to a string concatenation followed by an assignment.
On assigment by operation operators
There is a family of operators we can call assignment by xyz, where xyz here represents a binary operation on operands of the same type, such as addition, subtraction, concatenation.
So, let's say we have an operator ⊕: int
*int
→ int
, meaning that it takes a pair of int
s and produces another one:
⊕(a, b) = a ⊕ b
Let's say we want to calculate a
⊕b
and store the results on the variable a
. We can do so by:
a = a ⊕ b
But we do this so often when coding that an operator was created to represent the line above. You should take it as a single operation that does both the ⊕ operation and the assignment ( =
) with a single call:
a ⊕= b ⇔ a = a ⊕ b.
Some examples
So, in your case, you have a .=
operator. Now that you know about assignment by operation operators, you can guess that:
$query = "Hello, "
$query .= "World!";
is the same as:
$query = "Hello, "
$query = $query . "World!";
See?
Now, another frequent use of this kind operators are the +=
and -=
versions.
However, abuse of this kinds of operators may lead to less readable code (especially when dealing with "low level" operators acting on bits, for example).