可能重複:
Understanding Incrementing
Reference - What does this symbol mean in PHP?在PHP之前的東西什麼的++表示
什麼的++
手段,我也看到了這一點在JavaScript
$this->instance = ++self::$instances;
最佳注目小號
可能重複:
Understanding Incrementing
Reference - What does this symbol mean in PHP?在PHP之前的東西什麼的++表示
什麼的++
手段,我也看到了這一點在JavaScript
$this->instance = ++self::$instances;
最佳注目小號
的PHP documentation是非常有幫助的位置:
Example Name Effect
-----------------------------------------------------------------------
++$a Pre-increment Increments $a by one, then returns $a.
$a++ Post-increment Returns $a, then increments $a by one.
你的代碼是相同的:
self::$instances = self::$instances + 1;
$this->instance = self::$instances;
$ X在這裏硬編碼爲10,但很容易成爲用戶輸入的一些整數值。
<?php
$x=10;
$count=0;
while($count<=10)
{
printf("<br/>%d", $x++);
$count++;
}// end while
?>
// 10打印出至20
參見$ X ++,它意味着使用x的值然後通過遞增1(++ - > X = X + 1)。因此,我們打印出x爲10,遞增1並循環,打印出11等於1的增量。現在,如果我們有++ $ x,那麼我們將首先增加,然後打印出該值。因此,上面的++ $ x代碼將從11-21中打印出來,因爲當我們最初進入循環並且x = 10時,它會增加到11,然後打印。
查看$ count ++ ;,這個概念非常相似。我用它作爲一個計數器,讓while循環完全循環10次。 IT相當於count = count + 1;雖然將++放在$ x的左邊或右邊確實很重要,但數量並不重要,因爲我們不使用計數或將其打印出來。所以如果我在上面的代碼中有++ $ count,它會執行完全相同的操作。
http://php.net/manual/en/language.operators.increment.php – 2011-12-16 18:28:50
另請參見:[參考 - 這是什麼符號在PHP中的意思?](http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php)雖然這是一個很奇怪的情況,但這可能需要更多的解釋。你從哪裏得到這個代碼? – 2011-12-16 18:29:56