Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67946 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53516 invoked from network); 27 Jun 2013 14:19:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2013 14:19:07 -0000 Authentication-Results: pb1.pair.com header.from=florinpatan@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=florinpatan@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.180 as permitted sender) X-PHP-List-Original-Sender: florinpatan@gmail.com X-Host-Fingerprint: 209.85.214.180 mail-ob0-f180.google.com Received: from [209.85.214.180] ([209.85.214.180:52383] helo=mail-ob0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BF/C3-34034-9D94CC15 for ; Thu, 27 Jun 2013 10:19:06 -0400 Received: by mail-ob0-f180.google.com with SMTP id eh20so764275obb.39 for ; Thu, 27 Jun 2013 07:19:03 -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:content-transfer-encoding; bh=t4MrUtN8b7swwAfLTU8EdnxF/+o/t5DjVQlkRqSycaA=; b=aU8B0ruJ1nmsGiCfWf1sZiH3Qv/bXeqV39ilTWBQvlZKND4pok4fiHeeKHBTSf0vFF Hv2/LujGkt32+1vCSSxrI3RO/zSHSAHqmq+OMec6zmKaxA5RsFnsbSxmEzxWkHEbYkgY VCdBWfocR6QDrl/0ILgUJOaxCE0Lggzfzf5dgxUnRPGWLJaAAWvFo6fa55gGOiM5lCMG sXMESuAlCohK1y9dZY9MYpKVn9Bov8FOYwpEdgH2EKk2b2hzq+sv5veLO3dHbxJOsDPT xSnOZGJvOI0+aVJ/fLuEB6yCOMDUY4m2+de5IvNIvWXJylGEXAWAafaoY6WCvGOlp8RW cJ8w== X-Received: by 10.182.165.232 with SMTP id zb8mr4213158obb.101.1372342743412; Thu, 27 Jun 2013 07:19:03 -0700 (PDT) MIME-Version: 1.0 Received: by 10.76.18.161 with HTTP; Thu, 27 Jun 2013 07:18:33 -0700 (PDT) In-Reply-To: <4ED7146272E04A47B986ED49E771E347BB4DF6F344@Ikarus.ameusgmbh.intern> References: <4ED7146272E04A47B986ED49E771E347BB4DF6F344@Ikarus.ameusgmbh.intern> Date: Thu, 27 Jun 2013 16:18:33 +0200 Message-ID: To: Christian Stoller Cc: "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: florinpatan@gmail.com (Florin Patan) On Thu, Jun 27, 2013 at 4:10 PM, Christian Stoller wrot= e: > Hi internals, > > during my current work I had an idea for shorter array iteration with for= each. I haven=E2=80=99t seen such a syntax until now, but I think it is eas= y 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