Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62292 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53557 invoked from network); 20 Aug 2012 17:00:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Aug 2012 17:00:36 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 64.22.89.133 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 64.22.89.133 oxmail.registrar-servers.com Received: from [64.22.89.133] ([64.22.89.133:40930] helo=oxmail.registrar-servers.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4B/A0-07742-33D62305 for ; Mon, 20 Aug 2012 13:00:36 -0400 Received: from [192.168.0.200] (5ad3285b.bb.sky.com [90.211.40.91]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by oxmail.registrar-servers.com (Postfix) with ESMTPSA id 5A67175806F; Mon, 20 Aug 2012 13:00:29 -0400 (EDT) Message-ID: <50326D11.4090101@ajf.me> Date: Mon, 20 Aug 2012 18:00:01 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: Herman Radtke CC: Yasuo Ohgaki , Etienne Kneuss , Rasmus Lerdorf , Rasmus Schultz , internals@lists.php.net References: <502EB667.1020602@lerdorf.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] re: removing an item from an array From: ajf@ajf.me (Andrew Faulds) On 20/08/12 17:47, Herman Radtke wrote: >>> May be we should have something like >>>> array_delete_if($array, function($v, $k=null) { if ($v == 300) return >> true; }) >>> So 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. > > 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. > 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. 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½¢ :) -- Andrew Faulds http://ajf.me/