Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62300 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65965 invoked from network); 20 Aug 2012 18:08:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Aug 2012 18:08:14 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; 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:45456] helo=oxmail.registrar-servers.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B4/43-07742-C0D72305 for ; Mon, 20 Aug 2012 14:08:13 -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 E451A758043; Mon, 20 Aug 2012 14:08:08 -0400 (EDT) Message-ID: <50327CED.600@ajf.me> Date: Mon, 20 Aug 2012 19:07:41 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: Levi Morrison CC: Herman Radtke , Yasuo Ohgaki , Etienne Kneuss , Rasmus Lerdorf , Rasmus Schultz , internals@lists.php.net References: <502EB667.1020602@lerdorf.com> <50326D11.4090101@ajf.me> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] re: removing an item from an array From: ajf@ajf.me (Andrew Faulds) On 20/08/12 19:05, Levi Morrison wrote: > Some major points to consider for `array_delete`'s behavior: > > 1. Should items be compared with `==`, `===`, or custom comparison? If > we use `==` or `===` we'd probably add `array_udelete` to 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 `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? Use > `array_search` to find the index and unset it. If you want to reorder > the array you can use `array_search` to find the index and use > `array_slice`. Want to remove all instances of the value in the > array? Use `array_filter`. -- Andrew Faulds http://ajf.me/