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.

On Fri, Aug 17, 2012 at 5:23 PM, Rasmus Lerdorf <ras...@lerdorf.com> wrote:

> On 08/17/2012 05:21 PM, Rasmus Schultz wrote:
> >>
> >> if(($key = array_search($del_val, $messages)) !== false) {
> >>     unset($messages[$key]);
> >> }
> >>
> >> Nothing horrible here.
> >>
> >
> > I disagree - this is (or should be) a simple, atomic operation...
> > yet, you've got a function-call, an intermediary variable, a boolean
> test,
> > and an unset statement repeating the name of the array you're deleting
> from.
> >
> > This should be a simple statement or function/method-call, and in most
> > other languages it would be...
>
> Really? I can't think of a single language that has a call to remove an
> element by value in a key-value hash. Do you have some examples? What do
> you do with duplicates?
>
> -Rasmus
>
>

Reply via email to