Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62227 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24317 invoked from network); 17 Aug 2012 21:41:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Aug 2012 21:41:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; 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:39673] helo=mail-vc0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 09/6E-47492-37ABE205 for ; Fri, 17 Aug 2012 17:41:07 -0400 Received: by vcbgb30 with SMTP id gb30so3944904vcb.29 for ; Fri, 17 Aug 2012 14:41:04 -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=zS/CZlZP9EyHM7Do3XLo77FdQSRtfA62yGPaYqX3ZKA=; b=bdT8uJQnucWH8E6kCuwsx9FwvZmWDTlcSF8oPo2SxS7KLVZeChXCHQfDfXMM36WN0Q lvnBlbamJ5lsIk7btBrAx6GNoxhUmatSGbpsxJ1LKCWQ1NSi56eD+2FryEr9bmTSOQFK UeT/p2qycYs60F9uhxjANz7B+ErDwMiBjKcatfQRIbWhsAPrtoPGTjzbPGLnY4sWTfl2 +VKQDRNSyQtLlRoLf8EVtS4FbXG2NjWzY5m9V/fkf989DgxC2eXd4ctGUsTmunLM35Dl Dy7mV6qnigUeM+jrpaQIt8SA1vtUtzB4YNBO/NTbRDyEWEbZvYRHb0b/S6xXHfZ/+kLC fIwg== Received: by 10.52.98.101 with SMTP id eh5mr3124445vdb.8.1345239664750; Fri, 17 Aug 2012 14:41:04 -0700 (PDT) Received: from [192.168.102.150] ([69.38.252.85]) by mx.google.com with ESMTPS id bh5sm1520359vdc.16.2012.08.17.14.41.03 (version=SSLv3 cipher=OTHER); Fri, 17 Aug 2012 14:41:03 -0700 (PDT) Message-ID: <502EBA6E.9020603@lerdorf.com> Date: Fri, 17 Aug 2012 17:41:02 -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: <502EB667.1020602@lerdorf.com> In-Reply-To: X-Enigmail-Version: 1.5a1pre Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQl49NlrFtDR4D/pWKCwwrxWssUbfIeRAXDuekkCA4w0ILHOjoSgS11fKasUeLWSDIMHdc11 Subject: Re: [PHP-DEV] re: removing an item from an array From: rasmus@lerdorf.com (Rasmus Lerdorf) On 08/17/2012 05:35 PM, Rasmus Schultz wrote: > 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. The problem is that it is a rather unusual thing to do. I don't mean removing an element, that is very common, but you are implying that you know you don't have duplicates and you want a fast way to remove an element by value in that case. To me that means you built your array badly. If the values are unique then they should be the keys, or at least a representation of the value should be the key such that you don't need to scan the entire hash for the element when you need to access it. And removal is just like any other access. -Rasmus