On 17/08/12 22:41, Rasmus Lerdorf wrote:
On 08/17/2012 05:35 PM, Rasmus Schultz wrote:
Most other languages have more than one collection-type... since PHP has
only the single, hybrid array-type which acts both as a hash and as an
array, something like this ought to be available.

I don't know why everyone is so eager to jump up and argue against
something this simple, basic and useful. The fact that this is missing
is an oversight - just look at the number of solutions people come up
with. For what?

I want to remove and object from a list. Not an exotic and crazy
requirement, is it? It just isn't the sort of thing that should require
any substantial thinking or typing.

And it doesn't help make codebases more legible when people come up with
25 different ways to do it.
The problem is that it is a rather unusual thing to do. I don't mean
removing an element, that is very common, but you are implying that you
know you don't have duplicates and you want a fast way to remove an
element by value in that case. To me that means you built your array
badly. If the values are unique then they should be the keys, or at
least a representation of the value should be the key such that you
don't need to scan the entire hash for the element when you need to
access it. And removal is just like any other access.

-Rasmus


Hmm. I can think of a particular instance I've needed to remove an item from an array by value, and where keys wouldn't be an option. In PHP you can only have string or int keys, you can't have object keys. In Python, I've used Twisted (an excellent asynchronous OOP networking framework) to write client-server applications. One thing I did was maintain a list of clients (that is, a Python list). When a client disconnected, I would do list.remove(client). Of course there might be better ways to implement this, but it was simple and worked. Anything wrong with allowing the same in PHP?

--
Andrew Faulds
http://ajf.me/


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to