Re: Re: [PHP-DEV] removing an item from an array
| From: | Morgan L. Owens | Date: | Sun, 19 Aug 2012 06:54:34 +0000 |
| Subject: | Re: Re: [PHP-DEV] removing an item from an array | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62255@lists.php.net to get a copy of this message | ||
On 2012-08-19 04:08, Levi Morrison wrote:
On Sat, Aug 18, 2012 at 12:42 AM, Alexey Zakhlestin <indeyets@gmail.com> wrote:On 2012-08-19 10:18, Andrew Faulds wrote:On 16.08.2012, at 0:18, Rasmus Schultz <rasmus@mindplay.dk> wrote:There's already SplObjectStorage which CAN act like a Set for objects only. It's a terrible solution in my opinion and am working on creating a proper one. I don't know if that effort will be accepted, but I wanted to point out that a set already exists in the SPL. SplObjectStorage would indeed cover one given example:How come there is no straight-foward obvious way to simply remove a given value from an array?Well, this sounds like a reason for creating SplSet class
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? SplObjectStorage even has a detach() method for removing an element by value, as well as implementing the various array access interfaces.