Re: re: removing an item from an array
| From: | Andrew Faulds | Date: | Mon, 20 Aug 2012 17:44:45 +0000 |
| Subject: | Re: re: removing an item from an array | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62298@lists.php.net to get a copy of this message | ||
On 20/08/12 18:43, Sebastian Krebs wrote:
Am 20.08.2012 19:00, schrieb Andrew Faulds:On 20/08/12 17:47, Herman Radtke wrote:So you just want a convenient and readable way and you realise yourself, that it is really simple to implement. So: Why don't you just implement it yourself? function array_delete($array, $value) { // Your code here } What I don't understand is, why should every function goes directly into the core, if you can achieve exactly the same without core changes? I'd rather not argue any further about this (let's make an RFC and vote). I've already addressed this point.You seem a little arrogant. Arguably, a lot of array functions are unnecessary. But PHP is not supposed to be an extremely minimal language. Convenience functions are a good thing. We have array_pad for instance: completely unnecessary, you can do it manually with other array functions. Array_fill_keys and array_fill, too. array_flip is also unnecessary. Heck, who needs sorting, you can do that manually too. array_delete would be a more convenient, and more readable way to remove a value from an array. Yes, you can already remove array items, that's not the point. The point is this way is simpler and more convenient.You are basically asking to alias array_filter with "array_delete". That is a very slippery slope. I think array_filter is very a very obvious choice to remove something from an array. The "filter" function/method is common in functional languages (and functional frameworks like Underscore). These are things developers just need to learn as part of development. Really, this is entire thread should be on stack overflow, not internals.May be we should have something liketrue; })array_delete_if($array, function($v, $k=null) { if ($v == 300) returnSo array_filter?I'll use it or like for deleting, but the point of this thread is "intuitive function for deleting element(s)" array_delete($array, $value|callable) would be nicer for users, perhaps.
Regards, Sebastian-- Andrew Faulds http://ajf.me/Also, as someone else mentioned, PHP's universal collection datatype is a great thing. It is an associative array, it is a list, it is a tuple, it is a set, it can be used in many ways, it's incredibly versatile. Adding array_delete would allow you to use it like a set more easily. Just my 2½¢ :)