Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68003 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89231 invoked from network); 28 Jun 2013 09:21:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jun 2013 09:21:33 -0000 Authentication-Results: pb1.pair.com header.from=kontakt@beberlei.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=kontakt@beberlei.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain beberlei.de from 209.85.212.171 cause and error) X-PHP-List-Original-Sender: kontakt@beberlei.de X-Host-Fingerprint: 209.85.212.171 mail-wi0-f171.google.com Received: from [209.85.212.171] ([209.85.212.171:60371] helo=mail-wi0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 77/FC-34034-C955DC15 for ; Fri, 28 Jun 2013 05:21:33 -0400 Received: by mail-wi0-f171.google.com with SMTP id hj3so510509wib.4 for ; Fri, 28 Jun 2013 02:21:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:cc:content-type:x-gm-message-state; bh=nO3WQUmG6n9+C5XfuqI5DEG9D/N/c+SJFWGeEeUy8zA=; b=WiQ7JUsvPs1nSJJ66Kd20xD1HINIYlfwE6g5putrQU88c4spP31a4GvAVhTle0eWs6 jtg8YkMMhX1y7t2HTk1rHW/hx63dsT+k7qN4hITfRAZA0WGW1VD0HmQ8jOTnzyrTfp91 8t7gQGdS4bVAyzbw7D3HTnEbw1BIaNHbBY/U1B51bzY18jbGv8/3AdU9QufVQ/7zN/I5 x8K8yPOUwR9g7FconFRbJHiBfsJuoWY5IQIudSOfrSpQ6aW4pwmzgbvXJCSWdM1J4iQ0 d+UAlePwHjrfBbALGAaTIrtd4urFxCjDXWODrHM5otKV9YzSIPbtnf1jzDSESb2oFQSm UYWw== MIME-Version: 1.0 X-Received: by 10.194.157.99 with SMTP id wl3mr9024394wjb.76.1372411289780; Fri, 28 Jun 2013 02:21:29 -0700 (PDT) Received: by 10.194.175.161 with HTTP; Fri, 28 Jun 2013 02:21:29 -0700 (PDT) X-Originating-IP: [83.232.96.217] In-Reply-To: <4ED7146272E04A47B986ED49E771E347BB4DF6F344@Ikarus.ameusgmbh.intern> References: <4ED7146272E04A47B986ED49E771E347BB4DF6F344@Ikarus.ameusgmbh.intern> Date: Fri, 28 Jun 2013 11:21:29 +0200 Message-ID: To: Christian Stoller Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=089e0122f47c69daea04e0336776 X-Gm-Message-State: ALoCoQln/JrNBMRtXzYSeuH2T+yd8n7MJw5NlzmQZDWKgxSjTr2io0O4Z+KYqCWzMM0s3un3xEY5 Subject: Re: [PHP-DEV] New syntax for multidimensional array loop with foreach From: kontakt@beberlei.de (Benjamin Eberlei) --089e0122f47c69daea04e0336776 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable You can build an iterator to do this for you, doesn't need to be in the language IMHO 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 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 > --089e0122f47c69daea04e0336776--