i have following code for loop
for ($i=0; $i<=(count($subusers)-1); ++$i) {
is there a reason to use ++$i instead of $i++ if latter doing same thing?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
++$i is a micro-optimisation, it executes fractionally faster than $i++. However, unless the $subusers array is being changed within the loop so that count($subusers) can change from one iteration to the next, then any slight positive gain in speed is being negated (and then some) by counting the number of array entries every iteration.
Note that $i++ and ++$i would both execute at the end of each iteration of the loop. It isn’t the same as initialising $i to 1 rather than to 0.