Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67982 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12457 invoked from network); 27 Jun 2013 17:37:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2013 17:37:05 -0000 Authentication-Results: pb1.pair.com header.from=pierre@pcservice.co.za; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=pierre@pcservice.co.za; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain pcservice.co.za designates 69.93.179.5 as permitted sender) X-PHP-List-Original-Sender: pierre@pcservice.co.za X-Host-Fingerprint: 69.93.179.5 gateway13.websitewelcome.com Linux 2.6 Received: from [69.93.179.5] ([69.93.179.5:58529] helo=gateway13.websitewelcome.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6A/70-34034-0487CC15 for ; Thu, 27 Jun 2013 13:37:04 -0400 Received: by gateway13.websitewelcome.com (Postfix, from userid 5007) id AEF768DFD8780; Thu, 27 Jun 2013 12:36:51 -0500 (CDT) Received: from vinacomin.websitewelcome.com (vinacomin.websitewelcome.com [50.97.101.199]) by gateway13.websitewelcome.com (Postfix) with ESMTP id 9FE928DFD8759 for ; Thu, 27 Jun 2013 12:36:51 -0500 (CDT) Received: from [209.85.216.182] (port=52196 helo=mail-qc0-f182.google.com) by vinacomin.websitewelcome.com with esmtpsa (TLSv1:RC4-SHA:128) (Exim 4.80) (envelope-from ) id 1UsG7x-0007CP-Dg for internals@lists.php.net; Thu, 27 Jun 2013 12:37:01 -0500 Received: by mail-qc0-f182.google.com with SMTP id e10so698995qcy.13 for ; Thu, 27 Jun 2013 10:37:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=ciUMI3k1H/BGLvWGMEipd4tBjruHRm9yZ8lY2f0ZHXU=; b=XjPwsUFWcX9bodi1TB3PGgn5FRe9y78DcfRMUDB75hcj78GpAq9KdCEC0wmCahOUVY uzk/jG0hG7dGn2e1t+YUdpBIyjDtjCplMG1bcHjoXb1G+QSagqjwpOQW9sqw92CL5rkg 6iPQjHXO4ZxFp3qTT9NbtVIEkUmh9MX24UxuS05yvVRa41gvv7nBLp89UEP1eHaj91h+ HZBEJWqNy68+MiTTGsB/hOEMeuvIWePc3jhurHcEzLOHsAvmC+lZOOCmLiUfp7Ae0z54 MGib9VSfzT/ez/JgkSXVgHmSMcL4UgJDfIynHdBbi8vB07aFiMHIOM7JpclSwpajcjAH rZBQ== X-Received: by 10.224.36.143 with SMTP id t15mr13200015qad.60.1372354620245; Thu, 27 Jun 2013 10:37:00 -0700 (PDT) MIME-Version: 1.0 Reply-To: pierre@pcservice.co.za Received: by 10.49.76.179 with HTTP; Thu, 27 Jun 2013 10:36:30 -0700 (PDT) In-Reply-To: References: <4ED7146272E04A47B986ED49E771E347BB4DF6F344@Ikarus.ameusgmbh.intern> <1372349657.2376.4.camel@guybrush> Date: Thu, 27 Jun 2013 19:36:30 +0200 Message-ID: To: Tjerk Anne Meesters Cc: =?ISO-8859-1?Q?Johannes_Schl=FCter?= , Nikita Popov , Christian Stoller , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=089e0149d0f2a54d6904e026351d X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vinacomin.websitewelcome.com X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - pcservice.co.za X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (mail-qc0-f182.google.com) [209.85.216.182]:52196 X-Source-Auth: pierre@pcservice.co.za X-Email-Count: 9 X-Source-Cap: cGNzZXJ2aWM7cGllcnJlO3ZpbmFjb21pbi53ZWJzaXRld2VsY29tZS5jb20= Subject: Re: [PHP-DEV] New syntax for multidimensional array loop with foreach From: pierre@pcservice.co.za (Pierre du Plessis) --089e0149d0f2a54d6904e026351d Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Thu, Jun 27, 2013 at 7:29 PM, Tjerk Anne Meesters wrot= e: > 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> $value= ) { > > > > > $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 muc= h > > 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 with the $key and $innerKey. --089e0149d0f2a54d6904e026351d--