What is the difference between .= and += in PHP?
PHP中的。=和+ =有什么区别?
Quite simply, "+=" is a numeric operator and ".=" is a string operator. Consider this example:
$a = 'this is a ';
$a += 'test';
This is like writing:
$a = 'this' + 'test';
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:
$a = 10;
$a .= 5;
This is the same as writing:
$a = 10 . 5;
Since the "." operator is a string operator, it first converts the values to strings; and since "." means "concatenate," the result is the string "105".
The .
operator is the string concatenation operator. .=
will concatenate strings.
The +
operator is the addition operator. +=
will add numeric values.
。=是连接,+ =是加法
链接地址: http://www.djcxy.com/p/1830.html上一篇: 了解一行PHP
下一篇: 在PHP中。=和+ =有什么区别?