Concatenating Assignment Operator
During assignment, the computer will first evaluate everything to the right of the assignment operator and return a single value.
In the code above, the computer will concatenate the strings "Aisle" and " Nevertell" into the value "Aisle Nevertell".
One theme you may notice as you learn a programming language's syntax is that common actions that programmers need to do a lot often have a shortcut. Consider the following:
In the code above, we have the variable $full_name assigned the value "Aisle". We want to reassign $full_name to its current value appended with the string " Nevertell".
It will then assign this string as the value to the $full_name variable.
This is true even for more complex operations:
Believe it or not, this is such a common task that PHP offers a shorthand notation, the concatenating assignment operator (.=). Let's compare the same action but using this alternate operator:
It may seem funny to provide a shortcut to save just a few characters of typing, but when operations are performed often enough, those keystrokes can really add up. This syntax is also faster and easier to read which makes code easier to maintain.
One important thing to note is that even though PHP is often flexible about whitespace, it is inflexible with the concatenating assignment operator—the . and = characters must not have any spaces or other whitespace characters between them.
One important thing to note is that even though PHP is often flexible about whitespace, it is inflexible with the concatenating assignment operator—the . and = characters must not have any spaces or other whitespace characters between them.
Concatenating Assignment Operator
We can assign and reassign variables to the values that result from operations: