Re: Loop within Loop help please
| From: | John Nichel | Date: | Tue, 28 Sep 2004 19:17:17 +0000 |
| Subject: | Re: Loop within Loop help please | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-198109@lists.php.net to get a copy of this message | ||
Andrew Kreps wrote:
On Tue, 28 Sep 2004 10:45:19 -0700, Jason Davidson <jdavidson@zworg.com> wrote:You left this line out of Jason's post when you snipped it.... $count = 0; ie, everytime $count reached 20, run special code, and reset count to $20. -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 john@kegworks.comI see lots of references to modulus, which works fantastic.. but how abut just testing if its equal to 20, then there isnt that extra arthmitc call.. this is just another way to do the same thing.. take your pick.. unless someone can see a bad reason for this method. $count = 0; foreach ..... { if($count == 20) {The only thing wrong with this method is that it doesn't fit the.............problem's specifications. The original poster wanted a way totrigger the code every 20 iterations of an unknown sized loop (implying that the loop would have 40 or more items), whereas the solution above only triggers it on iteration 20. Other than that, it's a perfectly wonderful piece of code.