Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67947 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55052 invoked from network); 27 Jun 2013 14:23:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2013 14:23:19 -0000 Authentication-Results: pb1.pair.com header.from=robin@kingsquare.nl; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=robin@kingsquare.nl; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kingsquare.nl from 141.138.142.202 cause and error) X-PHP-List-Original-Sender: robin@kingsquare.nl X-Host-Fingerprint: 141.138.142.202 spring.kingsquare.nl Linux 2.6 Received: from [141.138.142.202] ([141.138.142.202:37065] helo=spring.kingsquare.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E5/24-34034-4DA4CC15 for ; Thu, 27 Jun 2013 10:23:17 -0400 X-No-Relay: not in my network Received: from mail-vb0-f54.google.com (mail-vb0-f54.google.com [209.85.212.54]) by spring.kingsquare.nl (Postfix) with ESMTPSA id 15E9FE9C753 for ; Thu, 27 Jun 2013 16:23:12 +0200 (CEST) Received: by mail-vb0-f54.google.com with SMTP id q12so688904vbe.27 for ; Thu, 27 Jun 2013 07:23:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=ww0JvAYGYR0zj6/r7xeD0eKNqFJG6+u2rGq68fQV22w=; b=XOvoAcSNWSwb+HWDtbmSs8IUYpdLAqX6EXhDkTMMjlID3SCJ13Z7RYRZdxRkWDybiV i2VSDxYHT1Iq/bCKhpPLwCpMsJ2ExTUf/oKqq59WFEanwf3hZfnPCWylmWPtlBmPjyTg gfHxEbyQDfBGhLGvRu/DIYBh6fPRhiz+qK52NR9GrJjPrmU8SWZmoWfow0BZdUKQRtVe mRggzAVm5/LxCK+1ZAWQ+qYCnjuurZjXTwCQRNdnm9n6jxqs+y88GQdwhbzWxYDCbnnU RuWXy4qxT59a9/GytajNBH3C1ozaiLpEFoCbKR7eSKvVtRKOeiXJpuEPBkVQ+0oXwbPu jy2Q== X-Received: by 10.58.31.106 with SMTP id z10mr3612715veh.61.1372342991993; Thu, 27 Jun 2013 07:23:11 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.203.7 with HTTP; Thu, 27 Jun 2013 07:22:51 -0700 (PDT) In-Reply-To: References: <4ED7146272E04A47B986ED49E771E347BB4DF6F344@Ikarus.ameusgmbh.intern> Date: Thu, 27 Jun 2013 16:22:51 +0200 Message-ID: To: Florin Patan Cc: Christian Stoller , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=089e013a2a628c467604e02380eb Subject: Re: [PHP-DEV] New syntax for multidimensional array loop with foreach From: robin@kingsquare.nl ("Kingsquare.nl - Robin Speekenbrink") --089e013a2a628c467604e02380eb Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I'd thought this would have been `solved` by allowing the list statement in foreach ( http://nl3.php.net/manual/en/control-structures.foreach.php#control-structu= res.foreach.list ) Doesnt that solve your problem already? Kind regards, Robin Speekenbrink 2013/6/27 Florin Patan > On Thu, Jun 27, 2013 at 4:10 PM, Christian Stoller > wrote: > > Hi internals, > > > > during my current work I had an idea for shorter array iteration with > foreach. I haven=E2=80=99t seen such a syntax until now, but I think it i= s easy to > understand ;-) > > > > Maybe you know the case where you have to iterate over all values of a > 2D (or more) array: > > > > $count =3D 0; > > foreach ($array as $key =3D> $innerArray) { > > foreach ($innerArray as $innerKey =3D> $value) { > > $count +=3D $value; > > // and do something with $key and $innerKey > > } > > } > > > > 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 > > } > > > > If the keys aren't needed, you can shorten it to: > > > > $count =3D 0; > > foreach ($array as $innerArray as $value) { > > $count +=3D $value; > > } > > > > What do you think? > > > > -- > > Christian Stoller > > LEONEX Internet GmbH > > > Hi, > > > Quick question, how would the engine then treat this case: > > $array =3D array(); > $array['level1.1']['level2']['level3'] =3D 'value'; > $array['level1.2'] =3D new StdClass(); > > foreach($array as $level1 as $level2 as $level3) { ... } > > > Best regards > ---- > Florin Patan > https://github.com/dlsniper > http://www.linkedin.com/in/florinpatan > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --089e013a2a628c467604e02380eb--