# removing an item from an array

- Thread: https://externals.io/message/62241
- Original archive: https://news-web.php.net/php.internals/62241
- Started by Morgan L. Owens on 2012-08-18T13:52:02+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #62241 — Morgan L. Owens — 2012-08-18T13:52:02+00:00

URL: https://externals.io/message/62241#62241

Rasmus Schultz wrote:

 > 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...

How simple is it? Does it:

1) Remove one occurrence of the element (presumably the first) or all?
2) Reindex the array (as someone else argued was necessary to make it 
"properly indexed" afterwards) or not?
3) Modify the array in-place or return a modified array?
4) Use type-strict or normal comparisons?

That's sixteen different interpretations of "remove a given value from 
an array" right there. Leave support for any of them out and someone is 
going to complain that they have to write a function to do what should 
be a "simple statement". Support all of them and there will probably 
_still_ be someone who wants their own particular set of circumstances 
catered for without having to write their own function to do it.

---

## #62251 — Morgan L. Owens — 2012-08-19T00:39:40+00:00

URL: https://externals.io/message/62241#62251

> 
> > […]
>
> So to answer you, 1) one, 2), no, 3) in-place, 4) type-strict (I don't
> see how a weakly-typed comparison for identifying an array value would
> help anyone).
So ... using a different definition of "value" than that used by 
 `array_search()` and `array_keys()`, then?

---

## #62252 — Andrew Faulds — 2012-08-19T00:43:19+00:00

URL: https://externals.io/message/62241#62252 · In reply to: #62251

> 
> > […]
> So ... using a different definition of "value" than that used by 
> `array_search()` and `array_keys()`, then?
>
Assuming you mean the strictness of comparison, you could have an 
optional $strict parameter defaulting to false like `array_search()`. (and 
hence non-strict by default)

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