Re: re: removing an item from an array
| From: | Andrew Faulds | Date: | Mon, 20 Aug 2012 18:07:41 +0000 |
| Subject: | Re: re: removing an item from an array | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62300@lists.php.net to get a copy of this message | ||
On 20/08/12 19:05, Levi Morrison wrote:
Some major points to consider forarray_delete's behavior: 1. Should items be compared with==,===, or custom comparison? If we use==or===we'd probably addarray_udeleteto allow a custom comparator. array_delete($array, $value, $all=false, $strict=false)
2. Should it stop when it encounters the first value that matches? If it does, should we add a function that searches in the reverse direction? ^
3. Should it modify the array in-place? If so, should we have another function that returns a copy of the array that does not include the removed value(s) instead? Modify in-place. No need for another, that's filter's job imo.
If someone wants to go through and define all of these cases and propose a patch, more power to them. Might do so.
----- Here are some reasons that aren't related to the above as to why I'm against adding-- Andrew Faulds http://ajf.me/array_delete: 1. PHP arrays are not sets. PHP arrays are meant to be a list and an associative array. As such, a PHP array can act as any* data structure that can be built from a list or associative array. A data structure that removes something by value is typically associated with a set and therefore does not belong in an array. 2. Using other array functions cover this use case AND do a better job. Want to remove the first instance of the value? Usearray_searchto find the index and unset it. If you want to reorder the array you can usearray_searchto find the index and usearray_slice. Want to remove all instances of the value in the array? Usearray_filter.