Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.php Subject: Re: break foreach loop after certain iteration and then start it Date: Sat, 5 Mar 2016 14:10:03 +0100 Lines: 54 Message-ID: <56DADAAB.2030504@arnowelzel.de> References: <6586983f-c3bc-4eb7-92a3-6035952e8cbb@googlegroups.com> <56D946D4.9030504@arnowelzel.de> <2056947.pXOX0CipXs@PointedEars.de> <56DAAC64.6010102@arnowelzel.de> <1522528.enTpbkXFfR@PointedEars.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net DaNfT3FoTxftmBRjEUmxhgkklhfl26NpcdEbZDyX+QELsA2PZC Cancel-Lock: sha1:Av8R7qMLJ6exh4yfq+FZDJpPQwM= In-Reply-To: <1522528.enTpbkXFfR@PointedEars.de> Xref: csiph.com comp.lang.php:16616 Thomas 'PointedEars' Lahn schrieb am 2016-03-05 um 11:46: > Arno Welzel wrote: > >> Thomas 'PointedEars' Lahn schrieb am 2016-03-05 um 02:28: >>> Arno Welzel wrote: >>>> >>> $counter = 0; >>>> >>>> foreach($mylist as $element) >>> ^^ >>>> { >>>> […] >>>> if($counter==3) >>> ^^ >>> Flow control statements should not be written like function calls. >> >> Which is a matter of style. > > Yes, therefore *I* said “should”. > >> I recognize flow control statements also when they are not formatted with >> a space preceding the first bracket ;-). >> >> But for beginners it may be helpful to distinguish between function >> calls and flow control. > > *PHP Standards Recommendations (PSR)-2* says it is a “MUST” and a “MUST NOT” > respectively, instead: When you want to follow those recommendations - yes. Nevertheless it is still valid code even when not following PSR. >> [...] >>> Or, if this is too confusing, >>> >>> if (($index + 1) % 3 === 0) >> >> […] >> When someone had enough knowledge to understand all this he would not >> ask here how to do something every third iteration within a foreach() >> loop. > > This is still not a PHP support forum, but a newsgroup for discussion about > PHP. Feel free not to answer or comment such questions at all. -- Arno Welzel http://arnowelzel.de http://de-rec-fahrrad.de http://fahrradzukunft.de