Re: in Operator

From: Date: Tue, 20 Jan 2015 09:27:23 +0000
Subject: Re: in Operator
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-80867@lists.php.net to get a copy of this message
2015-01-20 6:35 GMT+01:00 Pierre Joye <pierre.php@gmail.com>: > On Tue, Jan 20, 2015 at 6:15 AM, Andrea Faulds <ajf@ajf.me> wrote: >> Hi Mike, >> >>> On 20 Jan 2015, at 03:30, Mike Willbanks <pencap@gmail.com> wrote: >>> >>> I am very familiar with the in operator. However, the implementation >>> would be incomplete without handling loops via the in operator. Many >>> people when seeing an in operator also think of JavaScript. In that case >>> the in operator iterates over properties. As such in PHP we should be able >>> to iterate over associative arrays should the syntax be added. >>> >>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in >> >> Why? We already have foreach/as which does exactly that, and unlike JS which added for/of, >> there’s nothing wrong with PHP’s foreach so we don’t need support for a new symbol. > > Indeed, exactly same feature. > > Otherwise, well done again Andrea, love it ::) > > -- > Pierre > > @pierrejoye | http://www.libgd.org Hi Mike and Andrea, > In that case the in operator iterates over properties. As such in PHP we should be able to > iterate over associative arrays should the syntax be added. The reason why I didn't include this the reason Andrea mentioned: We already have foreach. > My assumption would be visible properties from the context which you are in. Yes, this is what I'd suggest. Regards, Nick

« previous php.internals (#80867) next »