Possible Duplicate:
Understanding Incrementing
Reference - What does this symbol mean in PHP?
What does the ++
means, I have seen this also in javascript
$this->instance = ++self::$instances;
Best Regards
Possible Duplicate:
Understanding Incrementing
Reference - What does this symbol mean in PHP?
What does the ++
means, I have seen this also in javascript
$this->instance = ++self::$instances;
Best Regards
The PHP documentation is quite helpful here:
Example Name Effect
-----------------------------------------------------------------------
++$a Pre-increment Increments $a by one, then returns $a.
$a++ Post-increment Returns $a, then increments $a by one.
Your code is equivalent to this:
self::$instances = self::$instances + 1;
$this->instance = self::$instances;
It's a pre-increment - http://php.net/manual/en/language.operators.increment.php
$x is hardcoded here as 10 but could easily be some integer value inputted by the user.
<?php
$x=10;
$count=0;
while($count<=10)
{
printf("<br/>%d", $x++);
$count++;
}// end while
?>
// prints out from 10 to 20.
See the $x++, it means use the value of x then increment by 1 (++ --> x=x+1). So we print out x which is 10, increment by 1 and the loop loops, print out 11 increment by 1 etc. Now if we have ++$x, then we would increment first and then print out the value. So the same code above with ++$x would print out from 11-21 since when we initially enter the loop and x=10, it is incremented to 11 and then printed.
See the $count++;, the very same concept. I used this as a counter to have the while loop loop 10 times exactly. IT's equivalent to count=count+1; While putting the ++ on the left or right for $x did matter, for the count it doesnt matter since we're not using count or printing it out. So if I had ++$count in the above code it would execute the exact same.