Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62265 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18078 invoked from network); 19 Aug 2012 21:58:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Aug 2012 21:58:12 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 74.125.82.170 mail-we0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:46201] helo=mail-we0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5A/38-03087-27161305 for ; Sun, 19 Aug 2012 17:58:11 -0400 Received: by weyr1 with SMTP id r1so4152156wey.29 for ; Sun, 19 Aug 2012 14:58:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=cr8kd/xOeJUdtKTkqSQY3oJ3tpffDZF0sDspOb1tQ24=; b=tz1qEJnIN7IstraJZ3ixTbh72rl2Lue4l77xWP42RqFD4yn5L1r1bvNnojeiprkzqY yaDcunNg+XKNqwFgr2qov+dCmPn3RBGV+T2b5PrQTumFwmgH860lg1bBe9VeI9zmIiGw jawbCFZLjISTck/OxIWCSIUtXsVjOOysNxJyb+/q1ZXAk9m15U8vUCn4lb998h4oKBA3 AxiwVaK4CLLIDwGQqsVQbBZBEq4dvGMx3yZbouedMt48W9dQHz9zkgwrWlmiDe9TLFE+ 9dwUdkUb1Ci73G768dpvxwJ63n8N7VFC0Z9R1E7yCcK1c6DukXDbWZq7d8MbXLDduR1w uAkA== Received: by 10.216.195.40 with SMTP id o40mr6450122wen.36.1345413488100; Sun, 19 Aug 2012 14:58:08 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.223.86.201 with HTTP; Sun, 19 Aug 2012 14:57:27 -0700 (PDT) In-Reply-To: <502EB667.1020602@lerdorf.com> References: <502EB667.1020602@lerdorf.com> Date: Mon, 20 Aug 2012 06:57:27 +0900 X-Google-Sender-Auth: N5nPU3WADXimNgTPgNbAE9NbBxA Message-ID: To: Rasmus Lerdorf Cc: 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: yohgaki@ohgaki.net (Yasuo Ohgaki) 2012/8/18 Rasmus Lerdorf : > 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? > Ruby can do (using irb) ruby-1.9.2-p180 :007 > h = {"apple"=>150, "banana"=>300, "lemon"=>300} => {"apple"=>150, "banana"=>300, "lemon"=>300} ruby-1.9.2-p180 :008 > h.delete_if { |k,v| v==300 } => {"apple"=>150} May be we should have something like array_delete_if($array, function($v, $k=null) { if ($v == 300) return true; }) -- Yasuo Ohgaki yohgaki@ohgaki.net