icklechurch Posted March 20, 2009 Share Posted March 20, 2009 Is it possible to get the number of the loop when you are in a foreach statement? For example I have the following foreach loop: <? foreach ($basket["records"] as $key => $record): LOTS OF CODE HERE ?> Is it possible to create an integer so that the first time the loop goes we have a variable called (for example) $i = 1...the second time it loops we have $i = 2 and so on?! Thanks! Link to comment https://forums.phpfreaks.com/topic/150297-foreach-loop-counting-please-help/ Share on other sites More sharing options...
dgoosens Posted March 20, 2009 Share Posted March 20, 2009 put $count = 0; before your foreach loop and $count++; in the foreach loop Link to comment https://forums.phpfreaks.com/topic/150297-foreach-loop-counting-please-help/#findComment-789325 Share on other sites More sharing options...
icklechurch Posted March 20, 2009 Author Share Posted March 20, 2009 it's that simple?! Brilliant! If only every problem could be solved with 2 lines of code, thank you Link to comment https://forums.phpfreaks.com/topic/150297-foreach-loop-counting-please-help/#findComment-789329 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.