Re: New syntax for multidimensional array loop with foreach

From: Date: Thu, 27 Jun 2013 14:27:52 +0000
Subject: Re: New syntax for multidimensional array loop with foreach
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-67950@lists.php.net to get a copy of this message
On 27.06.2013 16:10, Christian Stoller wrote: > Hi internals, > > during my current work I had an idea for shorter array iteration with foreach. I haven’t seen > such a syntax until now, but I think it is easy to understand ;-) > > Maybe you know the case where you have to iterate over all values of a 2D (or more) array: > > $count = 0; > foreach ($array as $key => $innerArray) { > foreach ($innerArray as $innerKey => $value) { > $count += $value; > // and do something with $key and $innerKey > } > } > > The new syntax could make it shorter and faster to write... but maybe it's a bit too > confusing? > > $count = 0; > foreach ($array as $key => $innerArray as $innerKey => $value) { > $count += $value; > // and do something with $key and $innerKey > } > What do you think? How would a break or continue on this behave? Would it end the inner or the outer circle? -- Ralf Lang Linux Consultant / Developer Tel.: +49-170-6381563 Mail: lang@b1-systems.de B1 Systems GmbH Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
« previous php.internals (#67950) next »