Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67948 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56625 invoked from network); 27 Jun 2013 14:25:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2013 14:25:39 -0000 Authentication-Results: pb1.pair.com header.from=krebs.seb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.174 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@gmail.com X-Host-Fingerprint: 209.85.212.174 mail-wi0-f174.google.com Received: from [209.85.212.174] ([209.85.212.174:44520] helo=mail-wi0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 41/84-34034-26B4CC15 for ; Thu, 27 Jun 2013 10:25:38 -0400 Received: by mail-wi0-f174.google.com with SMTP id k10so3168932wiv.7 for ; Thu, 27 Jun 2013 07:25:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=Z9slBArutopBpAw2I/jeQMsGBkbI74nU60ARijStycE=; b=hsRDVPtTNDRBEyFZqsFGDAKCCWuUU/r2U34MsFhSEfFycRk2YYyfKdqQn2mwfsWh7P 72cjc2cXVEqkZwgRdqjI0J48ng9ps57/UT1FJKqW/qRBxgVNiKf//UBN3qk17YmWeMoO JeJUuD/6E5Gj2Taq3b1Io2P20JpyBZv2yUIfRAB79IlE53/xgXbTanWg/EaPKO0u+eMY Iw07Zwhf/qRqq4+TdKfzmGjq91iqX3AR8FQ4RU4THam37MklEKLhjp74ZCVPQR5jsQKt GQtFcqU4emm08AxoeeZqWecBpPqrDwVjrVzOdp6XuzIfm/Z0s1cRHwbbbDu+3iqQeu0h zkwQ== X-Received: by 10.180.105.74 with SMTP id gk10mr16158704wib.3.1372343134557; Thu, 27 Jun 2013 07:25:34 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.176.6 with HTTP; Thu, 27 Jun 2013 07:24:54 -0700 (PDT) In-Reply-To: References: <4ED7146272E04A47B986ED49E771E347BB4DF6F344@Ikarus.ameusgmbh.intern> Date: Thu, 27 Jun 2013 16:24:54 +0200 Message-ID: To: "Kingsquare.nl - Robin Speekenbrink" Cc: Florin Patan , Christian Stoller , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=f46d04426ca60b9cf004e023895e Subject: Re: [PHP-DEV] New syntax for multidimensional array loop with foreach From: krebs.seb@gmail.com (Sebastian Krebs) --f46d04426ca60b9cf004e023895e Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 2013/6/27 Kingsquare.nl - Robin Speekenbrink > 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-struc= tures.foreach.list > ) > > Doesnt that solve your problem already? > This is only useable for structs, not for lists, or sets. > > 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=92t seen such a syntax until now, but I think it is ea= sy > 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 > > > > > --=20 github.com/KingCrunch --f46d04426ca60b9cf004e023895e--