Here is a short tutorial where you can find three helpful methods allowing to find the foreach index with the help of PHP.