Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62226 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22906 invoked from network); 17 Aug 2012 21:35:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Aug 2012 21:35:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.212.42 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.212.42 mail-vb0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:54110] helo=mail-vb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 09/1E-47492-539BE205 for ; Fri, 17 Aug 2012 17:35:50 -0400 Received: by vbbfs19 with SMTP id fs19so4309029vbb.29 for ; Fri, 17 Aug 2012 14:35:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:x-gm-message-state; bh=mGrBiRKfPrPC/3PTxIMcmZC615rNSb+Ce44+fjk0XjA=; b=lSPLgtvczt9saqEZHqccDsAjFnBYPU6aShfo0AZhmsN9oTpVfIM7ixZ1u801Bnl66X fOg6bBarhQ/qrJts9eGKXnBaLaeeOl0qxPomrHvHEXkGee9ozvBT6LPoqiiwKdq1lF45 XvrHwcNSE5rXbMyr/ES+dS+zygqyJphqI+jJN+MQPyDojDqN0jLXs+ZCkfV5wZFRv6/x jPovlZzuMcm8vF5sl6HshWbyX5o03pVPhsnD1X5o6lgLdt/ncZfAoXx9l/S0yC2YipUg NDH6QxUZkiYj5LoqrkyyL0pIrvkJvtdVHhGHgvHBs2dspfW1nMnkBXuHdX4zp3Yh0fv/ L+Ig== MIME-Version: 1.0 Received: by 10.52.36.76 with SMTP id o12mr3108333vdj.40.1345239346332; Fri, 17 Aug 2012 14:35:46 -0700 (PDT) Received: by 10.220.24.3 with HTTP; Fri, 17 Aug 2012 14:35:46 -0700 (PDT) In-Reply-To: <502EB667.1020602@lerdorf.com> References: <502EB667.1020602@lerdorf.com> Date: Fri, 17 Aug 2012 17:35:46 -0400 Message-ID: To: Rasmus Lerdorf Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=20cf307abe7d6042d204c77cf1b1 X-Gm-Message-State: ALoCoQm+GGtf2Dwxu77PfP9Wi2xFiL8C4e9EylGm0aHFARcySzC3OujT6XNHMiCvh+v2tv/3+caV Subject: Re: [PHP-DEV] re: removing an item from an array From: rasmus@mindplay.dk (Rasmus Schultz) --20cf307abe7d6042d204c77cf1b1 Content-Type: text/plain; charset=ISO-8859-1 Most other languages have more than one collection-type... since PHP has only the single, hybrid array-type which acts both as a hash and as an array, something like this ought to be available. I don't know why everyone is so eager to jump up and argue against something this simple, basic and useful. The fact that this is missing is an oversight - just look at the number of solutions people come up with. For what? I want to remove and object from a list. Not an exotic and crazy requirement, is it? It just isn't the sort of thing that should require any substantial thinking or typing. And it doesn't help make codebases more legible when people come up with 25 different ways to do it. On Fri, Aug 17, 2012 at 5:23 PM, Rasmus Lerdorf wrote: > On 08/17/2012 05:21 PM, Rasmus Schultz wrote: > >> > >> if(($key = array_search($del_val, $messages)) !== false) { > >> unset($messages[$key]); > >> } > >> > >> Nothing horrible here. > >> > > > > I disagree - this is (or should be) a simple, atomic operation... > > yet, you've got a function-call, an intermediary variable, a boolean > test, > > and an unset statement repeating the name of the array you're deleting > from. > > > > This should be a simple statement or function/method-call, and in most > > other languages it would be... > > Really? I can't think of a single language that has a call to remove an > element by value in a key-value hash. Do you have some examples? What do > you do with duplicates? > > -Rasmus > > --20cf307abe7d6042d204c77cf1b1--