Skip to content
heikijapan edited this page Oct 12, 2026 · 2 revisions

All other SMALL thins that one should know!!!

pre-increment and post-increment

  • ++$index this increments first and then outputs the value; if initial value is 0, then it outputs 1
  • $index++ it uses or echoes the initial value first and then increments it by 1
  • $index +=1 this is similar to pre-increment

Firstly, I had now idea that pre-increment actually existed. When pre-and post-increment used in a foreach loop then they will alter the index of iteration, but this $index + 1; will not change iteration index. Therefore you should be careful when using these in your projects.

Clone this wiki locally