。=运算符在PHP中意味着什么?

时间:2021-09-13 22:28:22

I have a variable that is being defined as

我有一个被定义为的变量

$var .= "value";

How does the use of the dot equal function?

如何使用点等功能?

4 个解决方案

#1


38  

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.

$ x。=与$ x = $ x不同。因为前者是就地的,但后者重新分配了$ x。

#2


14  

This is for concatenation

这是用于连接

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

echo $var; // this will give you testvalue

#3


5  

the "." operator is the string concatenation operator. and ".=" will concatenate strings.

“。” operator是字符串连接运算符。和“。=”将连接字符串。

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

“。=”运算符是一个字符串运算符,它首先将值转换为字符串;从那以后“。”表示连接/追加,结果是字符串“120”。

#4


0  

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!

结果将是:string(202)“120”,即变量的内容将改为120!不是1或20!

#1


38  

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.

$ x。=与$ x = $ x不同。因为前者是就地的,但后者重新分配了$ x。

#2


14  

This is for concatenation

这是用于连接

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

echo $var; // this will give you testvalue

#3


5  

the "." operator is the string concatenation operator. and ".=" will concatenate strings.

“。” operator是字符串连接运算符。和“。=”将连接字符串。

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

“。=”运算符是一个字符串运算符,它首先将值转换为字符串;从那以后“。”表示连接/追加,结果是字符串“120”。

#4


0  

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!

结果将是:string(202)“120”,即变量的内容将改为120!不是1或20!