Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62299 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64635 invoked from network); 20 Aug 2012 18:05:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Aug 2012 18:05:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:49355] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D6/F2-07742-97C72305 for ; Mon, 20 Aug 2012 14:05:46 -0400 Received: by lbbgp3 with SMTP id gp3so3556019lbb.29 for ; Mon, 20 Aug 2012 11:05:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=aUg+oZFoHzaeLm8LLQEQPQwgiMeuKawBugBLGrg7iCA=; b=ALluHkTwWKu0CLXV09SkrNFcamltFjE9WNtcWvVQwGKaiAVOr9+Q19E0RMWhAU88g8 vyi+yPVwvC/w2sRWLjCJAu5N+SoXQALkNfwov1KANqgBirbVXIbaR0jBbu5O61B15hd3 ADjJLGbcOrilAKEz3E+AxQN5Wk/3bjzg+Hr38dlqgGt2f5BbvgHpnT0W+VhqTq/FRqTl cPoSsTCiKqoAjg/nZhOCl+8ia9jpRtfsJYddxrvKAnnidSImxNhnSg7d6/MlZhyWxzSZ hcIINtJzH1p8Sc2r8YaA6xRdf+G02ehjzBMjDOq8bCQ6qfaGO4OzSEezOkKboO2/Cd6H Fijg== MIME-Version: 1.0 Received: by 10.112.36.130 with SMTP id q2mr6331599lbj.44.1345485942882; Mon, 20 Aug 2012 11:05:42 -0700 (PDT) Received: by 10.112.89.174 with HTTP; Mon, 20 Aug 2012 11:05:42 -0700 (PDT) In-Reply-To: References: <502EB667.1020602@lerdorf.com> <50326D11.4090101@ajf.me> Date: Mon, 20 Aug 2012 12:05:42 -0600 Message-ID: To: Andrew Faulds Cc: Herman Radtke , Yasuo Ohgaki , Etienne Kneuss , Rasmus Lerdorf , Rasmus Schultz , internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] re: removing an item from an array From: morrison.levi@gmail.com (Levi Morrison) 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. 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? If someone wants to go through and define all of these cases and propose a patch, more power to them. ----- 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`.