Asked • 05/30/19

How to find the foreach index?

Is it possible to find the `foreach` index? in a `for` loop as follows: for ($i = 0; $i < 10; ++$i) { echo $i . ' '; } `$i` will give you the index. Do I have to use the `for` loop or is there some way to get the index in the `foreach` loop?

1 Expert Answer


Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.


Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.