flying_circus wrote:Mordred wrote:Use ++$i instead of $i++.
I'm curious about this statement.
I'm not sure I understand the difference, could you please explain?
Me too. The only difference is in the return value: the expression ++$i returns the value of $i
after increasing it, and $i++ evaluates to the value
before increasing $i.
So for example, if $i is 5, then $j = ++$i; would result in $i and $j both being 6, whereas $j = $i++; would result in $j being 5 and $i being 6.
But since the result of the expression is not used here, it shouldn't make any difference at all..?
There are theoretical optimization considerations as why ++var would be faster than var++ (because then it doesn't have to maintain the original value, just the result) but that doesn't apply to PHP. And if this kind of speed improvement is an issue, then certainly PHP isn't suitable for this case in the first place
