Re: in Operator

From: Date: Tue, 20 Jan 2015 15:42:01 +0000
Subject: Re: in Operator
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-80880@lists.php.net to get a copy of this message
Mike Willbanks wrote on 20/01/2015 03:30:
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
I don't really see how this is related to the in operator, other than that some languages reuse the same keyword for both purposes. My immediate association when I saw this proposal was not "ah, like the loop syntax in JavaScript", but "ah, like the IN() operator in SQL". Given the ability to write foreach ( $foo as $key => $value ), I'm not sure adding a variant syntax of for ( $key in $foo ) has that much value for PHP. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#80880) next »