![]() |
Increment, decrement....
Hey guys,
Got a newbie and embarrassing question.... I thought that the ++ would add 1 to a number? Like so: Code:
$test = 1;Is the only way to use the ++ is in loops? I thought that the ++ was a quick way to add "1" without having to do this: $test2 = ($test + 1); |
You meant this:
Code:
$a = 1; |
For that use, you would need to use a pre-increment rather than post-increment operator. With your original code, using a post-increment, the expression
$test++ evaluates to 1 (this is used for the assignment) then the value is incremented. With a pre-increment, the expression ++$test evaluates to 2 which is used in the assignment to $test2Full details: http://php.net/operators.increment P.S. xenon beat me to it, both posts say the same thing. |
darn!!! Yes you guys are right!!
I forgot about doing ++$test... You know sometimes you are so used to doing: $i++ in your loops you forget you can do it the other way too!! Thanks guys!! |
Hehe. I know what you mean!
|
| All times are GMT. The time now is 10:48 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0