dreamwest Posted October 6, 2009 Share Posted October 6, 2009 I have a for loop and im trying to add the previous number to the next: for(blaablaa){ $total = 15; //first total is 15 second total is 2 echo $total; ++$total; } It just echos out 15 and 2 seperately, how can i add these so i get 17 Quote Link to comment https://forums.phpfreaks.com/topic/176663-cant-count-up/ Share on other sites More sharing options...
Bricktop Posted October 6, 2009 Share Posted October 6, 2009 Hi dreamwest, ++$total is the incorrect syntax, use something like: $grandtotal += $total; Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/176663-cant-count-up/#findComment-931371 Share on other sites More sharing options...
dreamwest Posted October 6, 2009 Author Share Posted October 6, 2009 That got it - Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/176663-cant-count-up/#findComment-931375 Share on other sites More sharing options...
KevinM1 Posted October 6, 2009 Share Posted October 6, 2009 To explain further, the ++ operator is the increment operator. It increases the value stored in the variable by 1. The += operator is shorthand. Example: $total = $total + $value; // is the same as $total += $value; Quote Link to comment https://forums.phpfreaks.com/topic/176663-cant-count-up/#findComment-931417 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.