What are the differences between .= and += in PHP?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Quite simply, “+=” is a numeric operator and “.=” is a string operator. Consider this example:
This is like writing:
The “+” or “+=” operator first converts the values to integers (and all strings evaluate to zero when cast to ints) and then adds them, so you get 0.
If you do this:
This is the same as writing:
Since the “.” operator is a string operator, it first converts the values to strings; and since “.” means “concatenate,” the result is the string “105”.