Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62225 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20750 invoked from network); 17 Aug 2012 21:23:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Aug 2012 21:23:58 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.220.170 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.220.170 mail-vc0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:44388] helo=mail-vc0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8E/9D-47492-C66BE205 for ; Fri, 17 Aug 2012 17:23:57 -0400 Received: by vcbgb30 with SMTP id gb30so3928638vcb.29 for ; Fri, 17 Aug 2012 14:23:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding:x-gm-message-state; bh=5QtDrQjXZZc7hZiEarvnrDfWvlfA3pVRhika6Cau+mA=; b=IOlzG/rCVMgQGJu9ZgEUVDhC8obxx62SSL3iv0zjKAdyIr/nicCX50jnafBUQybXoj KSiixsvcnZNqCrlsz/SbkDWhrxrRzWUdLidkH2q9YxcDCymghvFeQSHf5xO3FWJEkgW8 HnAulZqfFwIcSzZexi71fozvkXMUKNpzCxveqDztPRv5LxeEZczz08Vg/CH0tmLQoxmX ST33cxaO3/vBPljwKAZvwhK2PdndlKcDFoYQ1owrE7ej94uP3fUvJvhwJ2zzCY3OWKeQ Kx14Ifh+sHR+nY/DVI4+ggRdDCGq7nFitIRey4NqkinFmXEVpbxewMH7HPUfZ8Uu1441 8GFg== Received: by 10.52.100.229 with SMTP id fb5mr3106490vdb.102.1345238633968; Fri, 17 Aug 2012 14:23:53 -0700 (PDT) Received: from [192.168.102.150] ([69.38.252.85]) by mx.google.com with ESMTPS id xd6sm972501vec.7.2012.08.17.14.23.52 (version=SSLv3 cipher=OTHER); Fri, 17 Aug 2012 14:23:52 -0700 (PDT) Message-ID: <502EB667.1020602@lerdorf.com> Date: Fri, 17 Aug 2012 17:23:51 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: Rasmus Schultz CC: internals@lists.php.net References: In-Reply-To: X-Enigmail-Version: 1.5a1pre Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQnsCE9WoIprzdSYrv/lnKNuGQeCbaCyPmgjMC+vUV7lCkX2NF7E8RGHLPsLVCQ/CsnKPq0g Subject: Re: [PHP-DEV] re: removing an item from an array From: rasmus@lerdorf.com (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? -Rasmus