> > Why not apply the same approach to PHP? There is iterator_to_array() to > > convert a generator to an array, so we may not need both syntaxes. > > However, I think using [] for something that is *not an array* is > > counter-intuitive. > > No, I would definitely be for []-syntax producing an array. As I said, > that's in my experience what people usually want. >
In python comprehensions on [] makes a list and comprehensions in {} make a dictionary (list and dict comprehensions). As PHP only has one 'array' type using [] makes sense. Along that train of thought, should comprehensions also be possible in the old array() syntax? Does the proposal include comprehensions which build associative arrays? In python you can do {a['key'] : a for a in lst}, where lst is a list of dicts. I often use this to create a dictionary whose keys index a sub-element of a nested dictionary, as my example shows. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php