What does the .= operator mean in PHP?

一笑奈何 提交于 2019-11-29 15:59:40

问题


I have a variable that is being defined as

$var .= "value";

How does the use of the dot equal function?


回答1:


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.




回答2:


This is for concatenation

$var  = "test";
$var .= "value";

echo $var; // this will give you testvalue



回答3:


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".



来源:https://stackoverflow.com/questions/14846570/what-does-the-operator-mean-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!