Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67966 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86498 invoked from network); 27 Jun 2013 16:14:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2013 16:14:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 217.114.211.66 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 217.114.211.66 config.schlueters.de Received: from [217.114.211.66] ([217.114.211.66:53027] helo=config.schlueters.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6B/EA-34034-1E46CC15 for ; Thu, 27 Jun 2013 12:14:26 -0400 Received: from [192.168.2.20] (ppp-188-174-38-218.dynamic.mnet-online.de [188.174.38.218]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by config.schlueters.de (Postfix) with ESMTPSA id 8B7F765673; Thu, 27 Jun 2013 18:14:22 +0200 (CEST) To: Nikita Popov Cc: Christian Stoller , "internals@lists.php.net" In-Reply-To: References: <4ED7146272E04A47B986ED49E771E347BB4DF6F344@Ikarus.ameusgmbh.intern> Content-Type: text/plain; charset="UTF-8" Date: Thu, 27 Jun 2013 18:14:17 +0200 Message-ID: <1372349657.2376.4.camel@guybrush> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] New syntax for multidimensional array loop with foreach From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) On Thu, 2013-06-27 at 16:58 +0200, Nikita Popov wrote: > On Thu, Jun 27, 2013 at 4:10 PM, Christian Stoller wrote: > > > 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 > > } > > > > I'm against this feature. It makes the code marginally shorter, but a good > bit less readable. Combined with the break/continue issue, I don't think we > gain anything by introducing this syntax. +1 Let me add to this: While the pattern pattern exists often there are things to be done in the outer iteration, too. So I think the pure form ofthis double-foreach is not as common as it might seem ... And you can write foreach ($array as $i) foreach ($i as $innerKey => $value) { } it is not that much longer, but way more explicit on what is going on, visually parsing the suggested form needs more concentration. johannes