Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72347 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5585 invoked from network); 6 Feb 2014 20:32:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Feb 2014 20:32:03 -0000 Authentication-Results: pb1.pair.com header.from=are.you.winning@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=are.you.winning@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.170 as permitted sender) X-PHP-List-Original-Sender: are.you.winning@gmail.com X-Host-Fingerprint: 209.85.216.170 mail-qc0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:47001] helo=mail-qc0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8D/10-04585-141F3F25 for ; Thu, 06 Feb 2014 15:32:02 -0500 Received: by mail-qc0-f170.google.com with SMTP id e9so4241255qcy.29 for ; Thu, 06 Feb 2014 12:31:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=O3ekC24tTAWQnjxvhjpeWKNWevaTtLMkNAFi6sQkGAw=; b=j8wTqFjPf/tY49yxfU/MRqxBTr/clzh7psPSYututKT1lX7DNA03wcxjZYeCk8t0I2 s4nepyCqV8/vqCoMPsIRo8G70z+JEplkzG/YZMMNk1Vi/PiRNi86+LXsCXkgLsUG9Q18 7lYSSR/2QrPKMhKsUq2W5Vf1sg0Kf8e6w/uzT45sRHNd840MiKbL0p3z2/TZJ0qoGAI/ T/NUlcfR42QOM59HGEZG40XIl2fkKqFGV2kmJGPLRW5cE9d/4epXRvOwgIPiZ6UABXD2 924ZiEcbz6TKX9Na6ufxT1YhPfZzSo5cU5EAukF8poyZAhVMuLM70A7S2sNqKzag7mLo BZ+A== MIME-Version: 1.0 X-Received: by 10.140.102.242 with SMTP id w105mr14580062qge.74.1391718499711; Thu, 06 Feb 2014 12:28:19 -0800 (PST) Sender: are.you.winning@gmail.com Received: by 10.229.240.193 with HTTP; Thu, 6 Feb 2014 12:28:19 -0800 (PST) In-Reply-To: References: Date: Thu, 6 Feb 2014 20:28:19 +0000 X-Google-Sender-Auth: iUzdTrT4y5FZoP6nVeLDEricZcs Message-ID: To: Tjerk Meesters Cc: "Kingsquare.nl - Robin Speekenbrink" , PHP Internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] [discussion] add array_usearch() From: daverandom@php.net (Chris Wright) On 6 February 2014 19:55, Tjerk Meesters wrote: > Consider the following examples for finding a value in an array: > > array_search($value, $array, true); > > current(array_keys($array, $value, true)); > > key(array_filter($array, function($item) use ($value) { > return $item === $value; > })); > > Perhaps I've overlooked one way, but that's already three ways of doing > something similar; the difference lies in the memory behaviour, the first > being O(1) whereas the other two are O(n). I'm not sure where you got this statement from. array_search() is still O(n) in the worst case (when the needle is not found), which is the best you can hope for with such an operation. It's true that the other two are *always* O(n) whereas array_search() *could* return sooner than a complete iteration if the needle is found before the last element. My initial reaction to this is one of "ye gods, not another array_* function", but I wouldn't be against altering the existing array_search() so that the third parameter is a bitmask of flags, one of which could indicate that the search should be case insensitive. This could be done in a BC-compliant manner if the flag that indicates strict comparisons has a value of 1. Thanks, Chris