What does "++" mean in PHP?
Possible Duplicate:
Reference - What does this symbol mean in PHP?
I've been learning PHP by reading all sorts of things on the web. I've trying to figure out what this is called so I can look it up and read about it and learn how it works. It's the "++" in the code I'm assuming counts up so that the codes knows when to do a new line. I not looking for corrections to this code I'm looking for what the "++" is called so I can look it up.
$i = 0
if (++$i == 10) {
echo "new line";
}
It's called the prefix increment unary operator . It increments the number or character, then returns its value.
The postfix version does pretty much the same but returns its value first, then increments the variable.
That is a pre-increment. So in that code, $i
is first incremented (increased by one), and then its value is used to test for equality to 10.
So the code that you show essentially tests if 1 equals 10 (which it does not.)
It is a number operator named the prefix increment. It takes the previous stated number and adds 1 to it. You can find more information about arithmatic operators here: Howtoforge.com
链接地址: http://www.djcxy.com/p/9850.html上一篇: 轮询,Websockets,服务器
下一篇: “++”在PHP中意味着什么?