Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67950 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58528 invoked from network); 27 Jun 2013 14:28:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2013 14:28:01 -0000 Authentication-Results: pb1.pair.com smtp.mail=lang@b1-systems.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=lang@b1-systems.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain b1-systems.de designates 84.200.69.220 as permitted sender) X-PHP-List-Original-Sender: lang@b1-systems.de X-Host-Fingerprint: 84.200.69.220 mx1.b1-systems.de Received: from [84.200.69.220] ([84.200.69.220:35355] helo=mx1.b1-systems.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4A/E4-34034-EEB4CC15 for ; Thu, 27 Jun 2013 10:27:59 -0400 Received: from [192.168.1.17] (cable-158-181-84-94.cust.telecolumbus.net [158.181.84.94]) by mx1.b1-systems.de (Postfix) with ESMTPSA id 9B9584075 for ; Thu, 27 Jun 2013 16:23:59 +0200 (CEST) Message-ID: <51CC4BE8.4010203@b1-systems.de> Date: Thu, 27 Jun 2013 16:27:52 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: internals@lists.php.net References: <4ED7146272E04A47B986ED49E771E347BB4DF6F344@Ikarus.ameusgmbh.intern> In-Reply-To: <4ED7146272E04A47B986ED49E771E347BB4DF6F344@Ikarus.ameusgmbh.intern> X-Enigmail-Version: 1.6a1pre Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="----enig2FGVEQCDHNUKKBPMQAJLM" Subject: Re: [PHP-DEV] New syntax for multidimensional array loop with foreach From: lang@b1-systems.de (Ralf Lang) ------enig2FGVEQCDHNUKKBPMQAJLM Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 27.06.2013 16:10, Christian Stoller wrote: > Hi internals, >=20 > during my current work I had an idea for shorter array iteration with f= oreach. I haven=E2=80=99t seen such a syntax until now, but I think it is= easy to understand ;-) >=20 > Maybe you know the case where you have to iterate over all values of a = 2D (or more) array: >=20 > $count =3D 0; > foreach ($array as $key =3D> $innerArray) { > foreach ($innerArray as $innerKey =3D> $value) { > $count +=3D $value;=20 > // and do something with $key and $innerKey > } > } >=20 > The new syntax could make it shorter and faster to write... but maybe i= t's a bit too confusing? >=20 > $count =3D 0; > foreach ($array as $key =3D> $innerArray as $innerKey =3D> $value) { > $count +=3D $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? --=20 Ralf Lang Linux Consultant / Developer Tel.: +49-170-6381563 Mail: lang@b1-systems.de B1 Systems GmbH Osterfeldstra=C3=9Fe 7 / 85088 Vohburg / http://www.b1-systems.de GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537 ------enig2FGVEQCDHNUKKBPMQAJLM Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlHMS+oACgkQCs1dsHJ/X7BDfQCgv/ufX4zTTuf1ct3IY2iRS0ZK TgkAoK4h28m43mHRFvHG+HQuk41E4zB2 =2cVM -----END PGP SIGNATURE----- ------enig2FGVEQCDHNUKKBPMQAJLM--