Re: Foreach loop syntax

From: Date: Wed, 15 Aug 2001 05:15:55 +0000
Subject: Re: Foreach loop syntax
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-62769@lists.php.net to get a copy of this message
> Ok, I asked a similar question more than a year ago, so I apologize for > being a little redundant :) > > Why was PHP's foreach loop syntax chosen to be > > foreach($dogs as $dog){} > > instead of something more common (Python, Javascript, can't think what else > right now) and, to me, more intuitive, like > > foreach($dog in $dogs){} > > Just wondering what the reasoning was. Thanks. Wild Speculation: Well, we needed the variant of: foreach($dogs as $index=>$dog){} and we already had the perfectly fine: while (list($index, $dog) = each($dogs)){} and if we did it your way, it wouldn't be all that different from that :-) [asbestos on] Disclaimer: I haven't even figured out why anybody wanted the damn thing in the first place. Clutters up the language and provides no new functionality. :-) [asbestos off] If you really wanna know, go read the source and find out who added it, and ask them, or check the PHP-DEV archives where I'm betting it was argued at length how to do it. -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#62769) next »