本文介绍了PHP中.=和+ =有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
.=和+ =在PHP中有什么区别?
What are the differences between .= and += in PHP?
推荐答案
很简单,"+ ="是数字运算符,而.="是字符串运算符.考虑以下示例:
Quite simply, "+=" is a numeric operator and ".=" is a string operator. Consider this example:
$a = 'this is a ';
$a += 'test';
这就像写作:
$a = 'this' + 'test';
"+"或"+ ="运算符首先将值转换为整数(当转换为int时,所有字符串求值为零),然后将它们相加,因此得到0.
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.
如果您这样做:
$a = 10;
$a .= 5;
这与写作相同:
$a = 10 . 5;
自." operator是一个字符串运算符,它首先将值转换为字符串;并且因为."表示连接",结果是字符串"105".
Since the "." operator is a string operator, it first converts the values to strings; and since "." means "concatenate," the result is the string "105".
这篇关于PHP中.=和+ =有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!