Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:4875 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50281 invoked by uid 1010); 19 Oct 2003 11:36:04 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 50257 invoked from network); 19 Oct 2003 11:36:03 -0000 Received: from unknown (HELO smtpzilla5.xs4all.nl) (194.109.127.141) by pb1.pair.com with SMTP; 19 Oct 2003 11:36:03 -0000 Received: from amdk6.xs4all.nl (a213-84-38-246.adsl.xs4all.nl [213.84.38.246]) by smtpzilla5.xs4all.nl (8.12.9/8.12.9) with ESMTP id h9JBa2dK019996 for ; Sun, 19 Oct 2003 13:36:02 +0200 (CEST) Message-ID: <5.1.0.14.0.20031015055440.03dce0d0@localhost> X-Sender: ganswijk@pop.xs4all.nl@localhost X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Sun, 19 Oct 2003 13:35:39 +0200 To: internals@lists.php.net Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Subject: alternative for foreach () From: ganswijk@xs4all.nl (Jaap van Ganswijk) Hi all, I'd like to propose an alternative for the foreach statement. Of course the construct: while (list($i,$d)=each($A)) is much harder to read than: foreach ($A as $i=>$d) and although I had doubts at first I'm currently rewriting all my old scripts to the new format whenever I encounter them, but I would have much rather seen that this problem hadn't been solved using a new statement but with a new operator like: while (each $i=>$d in $A) or shorter: while ($i=>$d in $A) I think that my solution to the problem has several advantages: 1. It's possible to use the in-operator as part of a more complex expression like: for (;$d in $A and $t++<10;) //I use this a lot temporarily //in the testing phase of scripts It would even be possible to write something like: while ($d in $D and $e in $E) { $A[]=$d+$e; } 2. Rewriting old code is much easier because the variables stay in the same order. 3. One is free to use a while or a for statement. I wouldn't bring this matter up if it already was 'water under the bridge', but this syntax doesn't conflict with the foreach syntax, so I'm just suggesting that my syntax is added too, so people can choose what they use. It wouldn't surprise me when the foreach syntax would be deprecated soon... Greetings, Jaap