Pre-increment and post-increment aren't the same

Take advantage of the fact that PHP allows you to post-increment ($i++) and pre-increment (++$i). The meaning is the same as long as you are not writing anything like $j = $i++, however pre-incrementing is about 10% faster even as of PHP 5.6, which means that switching from post-incrementing to pre-incrementing is perfect for micro-optimisation pedants!

In practice, the difference between the two is so small you wouldn't notice. That said, it's an easy habit to change, so why not?


Next chapter: Don't think that using references will lower your RAM usage >>

Previous chapter: Get your loops right first

Jump to:


Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.