Skip to content
Advertisement

PHP How to determine the first and last iteration in a foreach loop?

The question is simple. I have a foreach loop in my code:

JavaScript

In this loop, I want to react differently when we are in first or last iteration.

How to do this?

Advertisement

Answer

You could use a counter:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement