Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62266 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19981 invoked from network); 19 Aug 2012 22:19:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Aug 2012 22:19:56 -0000 Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.42 as permitted sender) X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.210.42 mail-pz0-f42.google.com Received: from [209.85.210.42] ([209.85.210.42:63831] helo=mail-pz0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0F/88-03087-48661305 for ; Sun, 19 Aug 2012 18:19:49 -0400 Received: by dalf4 with SMTP id f4so1768192dal.29 for ; Sun, 19 Aug 2012 15:19:45 -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=vfyIMIB4l7mclUEccn0VbihKg7B+AUChE+RXffWRzFA=; b=KGhrxQnImneezCvrP3I79QsqCVfV1evWXZMqqKEIqzBjPEKsPKCD8ZK4dEcOCw2RU7 udfwGEZ9XjIihhXjCEepULaxyI20WeT4qhBT8je0+4iOU3THWK4E9TQXcLRFoCASCeui pRonpsodUvqsfCBAgVhbsqOJTirsAMOlEj5QqWb/IxQAH6E/z18VDMneSEBIp8nK6Hb2 rhhH5pjs8SFKHEPr0+LttazeXfbkQcz+y2hLkk37eoEe+6F4ZnXqaOIhIjgG1wRkuErG sk3hjW/17hE5HDlC5bjqUW3WBDkVz+BQDjG4E2zakOd0DjX71EQ/RBKehETYCiIJoaks fS6g== Received: by 10.68.224.161 with SMTP id rd1mr10289540pbc.133.1345414785459; Sun, 19 Aug 2012 15:19:45 -0700 (PDT) MIME-Version: 1.0 Sender: ekneuss@gmail.com Received: by 10.68.196.226 with HTTP; Sun, 19 Aug 2012 15:19:25 -0700 (PDT) In-Reply-To: References: <502EB667.1020602@lerdorf.com> Date: Mon, 20 Aug 2012 00:19:25 +0200 X-Google-Sender-Auth: h0D5NZorPo_aIwzBMYDHiEA090k Message-ID: To: Yasuo Ohgaki Cc: Rasmus Lerdorf , Rasmus Schultz , internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] re: removing an item from an array From: colder@php.net (Etienne Kneuss) On Sun, Aug 19, 2012 at 11:57 PM, Yasuo Ohgaki wrote: > 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; }) So array_filter? > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > -- Etienne Kneuss http://www.colder.ch