Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62297 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61424 invoked from network); 20 Aug 2012 17:43:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Aug 2012 17:43:20 -0000 Authentication-Results: pb1.pair.com header.from=krebs.seb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.42 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@gmail.com X-Host-Fingerprint: 209.85.214.42 mail-bk0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:49219] helo=mail-bk0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FF/42-07742-73772305 for ; Mon, 20 Aug 2012 13:43:19 -0400 Received: by bkcjm19 with SMTP id jm19so2151664bkc.29 for ; Mon, 20 Aug 2012 10:43:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=5K3e9QL4Vl9Mw7QitT+GdkJfI9PPDgfq5MvZ+MSUhKU=; b=t2yKKeHVyn6WdO7+c0JipsEhr9O9bQtneF8qclIxa8NJYiGixLzJNsPrdQ4bNuQuyo ztD8cydUGmzPezUHJKXK2Szz4kVtg0Nm6gsfbhMF6p+iCVyCz/b1NJuzLfyshR7bYwPs dVyARMVNf594K1i/4UDA5snYu7QEZ01DRp9N5ks6AsagRQ7RBGB/hlXjKbCLE7bUR8II qWqEiOHWW7LdAJJ8ZHs122GxIDAhZqysic4+UjPLKNEDf+yfE33mN7GMXLpuwUpXZW1R /t6lLQ0eEdmHaZ6YGTUNjakrhGoIuKFm7tvheUOyVFnQopL4xwqI3sQGYPOGBU7ao6L1 +QoQ== Received: by 10.204.157.151 with SMTP id b23mr4600116bkx.96.1345484596434; Mon, 20 Aug 2012 10:43:16 -0700 (PDT) Received: from [192.168.24.2] (91-66-42-108-dynip.superkabel.de. [91.66.42.108]) by mx.google.com with ESMTPS id j9sm6587210bkv.0.2012.08.20.10.43.15 (version=SSLv3 cipher=OTHER); Mon, 20 Aug 2012 10:43:15 -0700 (PDT) Message-ID: <50327733.6060302@googlemail.com> Date: Mon, 20 Aug 2012 19:43:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: internals@lists.php.net References: <502EB667.1020602@lerdorf.com> <50326D11.4090101@ajf.me> In-Reply-To: <50326D11.4090101@ajf.me> 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: krebs.seb@gmail.com (Sebastian Krebs) Am 20.08.2012 19:00, schrieb 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. 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? Regards, Sebastian > > 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½¢ :) >