Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67977 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4566 invoked from network); 27 Jun 2013 17:09:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2013 17:09:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=patrick.allaert@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=patrick.allaert@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.171 as permitted sender) X-PHP-List-Original-Sender: patrick.allaert@gmail.com X-Host-Fingerprint: 209.85.214.171 mail-ob0-f171.google.com Received: from [209.85.214.171] ([209.85.214.171:35454] helo=mail-ob0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 80/CE-34034-CD17CC15 for ; Thu, 27 Jun 2013 13:09:49 -0400 Received: by mail-ob0-f171.google.com with SMTP id dn14so980206obc.2 for ; Thu, 27 Jun 2013 10:09:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=yHaOsawsB67j2a4XavhejXHx/VahPlrp737xYNO/xyg=; b=TSeEyhtAtwLKB5gPs9fEMdsKYrzOr/2Ke9CgNVo1rOowV6ZFFwOKhW07PTPk6/pZFD CiOqdZpApFawXUC0V/QnwiF5GTipcW9L7BNi5eqYuIPBOjgbBSLf7xNmhXiVB+pLRrRD StTkGM4HxxILxDKEEXS9dmOe7/nbWU0/69Qt0wBVUV6ruLybDvQYNr9ovvXbzh2ecMqr A0bpafpxuQGR19S5aQtn9b4C33LfnUv4vpRa/a/wLe48VXLiRpDV4VwpFHisWcDgqKwU yyXnK1I07kNMuA8SGGTbWI1GYOBdrT791JwHAeGlUWO7mkCIoIvnk1//dMg1BMKSl4Hy ZmBg== MIME-Version: 1.0 X-Received: by 10.60.16.225 with SMTP id j1mr3309744oed.97.1372352986277; Thu, 27 Jun 2013 10:09:46 -0700 (PDT) Sender: patrick.allaert@gmail.com Received: by 10.76.7.169 with HTTP; Thu, 27 Jun 2013 10:09:46 -0700 (PDT) In-Reply-To: <1372349657.2376.4.camel@guybrush> References: <4ED7146272E04A47B986ED49E771E347BB4DF6F344@Ikarus.ameusgmbh.intern> <1372349657.2376.4.camel@guybrush> Date: Thu, 27 Jun 2013 19:09:46 +0200 X-Google-Sender-Auth: Sz-4mJpzN6kOuxTJbTK1yhjnfKk Message-ID: To: =?UTF-8?Q?Johannes_Schl=C3=BCter?= Cc: Nikita Popov , Christian Stoller , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] New syntax for multidimensional array loop with foreach From: patrickallaert@php.net (Patrick ALLAERT) 2013/6/27 Johannes Schl=C3=BCter : > On Thu, 2013-06-27 at 16:58 +0200, Nikita Popov wrote: >> On Thu, Jun 27, 2013 at 4:10 PM, Christian Stoller wr= ote: >> >> > The new syntax could make it shorter and faster to write... but maybe = it's >> > a bit too confusing? >> > >> > $count =3D 0; >> > foreach ($array as $key =3D> $innerArray as $innerKey =3D> $value) { >> > $count +=3D $value; >> > // and do something with $key and $innerKey >> > } >> > >> >> I'm against this feature. It makes the code marginally shorter, but a go= od >> 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 =3D> $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 +1 to what Nikita and Johannes said.