Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67983 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14591 invoked from network); 27 Jun 2013 17:58:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2013 17:58:01 -0000 Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.49 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.128.49 mail-qe0-f49.google.com Received: from [209.85.128.49] ([209.85.128.49:59520] helo=mail-qe0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 68/D0-34034-82D7CC15 for ; Thu, 27 Jun 2013 13:58:01 -0400 Received: by mail-qe0-f49.google.com with SMTP id cz11so341501qeb.36 for ; Thu, 27 Jun 2013 10:57:58 -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; bh=c4sw9Nn1o059tIP8EtmPI0M5I93AjBjSpAwTIk549Bw=; b=fe/zfELx5ZUDbSDTLiasqn2It4DMR3eIlsLyu87hF8fJC+lI8xDbbLDMR9sdbq4BId zBnUegLyKaxkdUhQvw7MGvia6elxQXBOxpCbDNiGuihjIyRzQp0tY74I4YpnPbS0K8XY OvHcpLbb4oqeN2eOmzRU1Eswl1LyfrjPFrEKJysVu9YAkvymZ7fdIxvvWZH+fGImekjl zBXWqM7JV8QmD1hPLSBHt6bfK0PcRYY4WbWRzCdtXFU0J2JN94rj4hQ8QzFQUjfm7SAm AGaNGf9L32j7fhp4MByTketRbnpHy6iT1gelem32C3Spa7Yy203C+p3cvOUQ7Lqxig+N EZyg== MIME-Version: 1.0 X-Received: by 10.49.29.106 with SMTP id j10mr12411287qeh.37.1372355878117; Thu, 27 Jun 2013 10:57:58 -0700 (PDT) Sender: tjerk.meesters@gmail.com Received: by 10.49.99.67 with HTTP; Thu, 27 Jun 2013 10:57:58 -0700 (PDT) In-Reply-To: References: <4ED7146272E04A47B986ED49E771E347BB4DF6F344@Ikarus.ameusgmbh.intern> <1372349657.2376.4.camel@guybrush> Date: Fri, 28 Jun 2013 01:57:58 +0800 X-Google-Sender-Auth: pNl5z_hvxi_j2TT858AAt0VCdCM Message-ID: To: pierre@pcservice.co.za Cc: =?ISO-8859-1?Q?Johannes_Schl=FCter?= , Nikita Popov , Christian Stoller , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7bdca4789eec9904e026804e Subject: Re: [PHP-DEV] New syntax for multidimensional array loop with foreach From: datibbaw@php.net (Tjerk Anne Meesters) --047d7bdca4789eec9904e026804e Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Fri, Jun 28, 2013 at 1:36 AM, Pierre du Plessis wrote: > On Thu, Jun 27, 2013 at 7:29 PM, Tjerk Anne Meesters wr= ote: > >> On Fri, Jun 28, 2013 at 1:13 AM, Pierre du Plessis >> wrote: >> >> > On Thu, Jun 27, 2013 at 6:14 PM, Johannes Schl=FCter >> > wrote: >> > >> > > On Thu, 2013-06-27 at 16:58 +0200, Nikita Popov wrote: >> > > > On Thu, Jun 27, 2013 at 4:10 PM, Christian Stoller < >> stoller@leonex.de >> > > >wrote: >> > > > >> > > > > 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> $valu= e) { >> > > > > $count +=3D $value; >> > > > > // and do something with $key and $innerKey >> > > > > } >> > > > > >> > > >> > >> > With the addition of array_column in php 5.5, this can be done in a mu= ch >> > cleaner way: >> > >> > $array =3D array( >> > array('value' =3D> 1), >> > array('value' =3D> 2), >> > array('value' =3D> 3), >> > ); >> > >> > $count =3D 0; >> > >> > foreach(array_column($array, 'value') as $value) { >> > $count +=3D $value; >> > } >> > >> >> And what about the "// and do something with $key and $innerKey" part? > > > This is using the original example provided, which didn't do anything wit= h > the $key and $innerKey. > It's good to see how you have developed a keen sense of code optimization; however, that's not doing much good here, because the intention of the shown code is that those variables are actually used, which is what the commented line conveys :) --=20 -- Tjerk --047d7bdca4789eec9904e026804e--