On 2012-08-19 04:08, Levi Morrison wrote:
On Sat, Aug 18, 2012 at 12:42 AM, Alexey Zakhlestin <indey...@gmail.com> wrote:
On 16.08.2012, at 0:18, Rasmus Schultz <ras...@mindplay.dk> wrote:
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
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:
On 2012-08-19 10:18, Andrew Faulds wrote:
> 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.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php