Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85297 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39480 invoked from network); 20 Mar 2015 14:56:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Mar 2015 14:56:54 -0000 Authentication-Results: pb1.pair.com header.from=bowersbros@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=bowersbros@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.171 as permitted sender) X-PHP-List-Original-Sender: bowersbros@gmail.com X-Host-Fingerprint: 209.85.212.171 mail-wi0-f171.google.com Received: from [209.85.212.171] ([209.85.212.171:38206] helo=mail-wi0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 14/19-21731-8F43C055 for ; Fri, 20 Mar 2015 09:55:52 -0500 Received: by wibgn9 with SMTP id gn9so16823357wib.1 for ; Fri, 20 Mar 2015 07:55:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=ayqDHqORBZyTNCGwzhDCUvF0MKepaUm1oykV2BH3yWM=; b=cAlWG/iKhGipy9RqduN0ssv8uh2xV3u4hUIKpminGXeodweiwsBY5meayiXBLcKsGN h3P+9ofnyTIPQnrPCr/US+WwtOzpI6duF4ilG2Ee8c83wmq54wzjQ4+oB4z5q75By0zE mPgihlfILdAWOMsEaVM67pwfLiKV4l/JsptUwPM6BLaAn7n3H+NAnefHpyT7yfA5IzuB U92OptRqzKF/fIwA0hCiREGmP1I1X4tUE5TslU91itQl7jK1EX1h3puhp7dbPwVOvGvH fvG4xPVnWu3HYYxCnHEhPM3DIE5qPJUsz3Bs60jRFDPSHTzmxhM2E971hnVLN3nN9hjM Aoog== MIME-Version: 1.0 X-Received: by 10.180.206.13 with SMTP id lk13mr5871683wic.35.1426863349948; Fri, 20 Mar 2015 07:55:49 -0700 (PDT) Received: by 10.28.62.84 with HTTP; Fri, 20 Mar 2015 07:55:49 -0700 (PDT) In-Reply-To: <550C317E.8020508@gmail.com> References: <550B5A81.1090706@gmail.com> <550B7189.4040608@gmail.com> <7486C296-7535-4633-AFE2-02E7BBC67BC5@gmail.com> <550C1176.9050307@gmail.com> <550C1AE4.8090607@gmail.com> <550C1EC3.8000106@gmail.com> <550C317E.8020508@gmail.com> Date: Fri, 20 Mar 2015 14:55:49 +0000 Message-ID: To: Rowan Collins Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=001a11c37f9c1de9850511b9834d Subject: Re: [PHP-DEV] RFC - Array slice syntactic sugar From: bowersbros@gmail.com (Alex Bowers) --001a11c37f9c1de9850511b9834d Content-Type: text/plain; charset=UTF-8 > > So $dictionary['elephant':'snake'] returns all elements with keys which > sort lexically between 'elephant' and 'snake', regardless of whether the > array is sorted. Makes sense to me. Alternatively, a key-based slice could look up the position in the array of > the two keys, and then perform a positional slice between those positions, > i.e. $array[$a:$b] == $array[ @ key_position($array, $a) : > key_position($array, $b) ]. I'm not sure that's particularly intuitive or > useful, but again, it has no problem with string keys. I'd say no to that, since it is not an obvious use case, since if you are defining associated arrays, going for the indexes of those fields feels strange; since one of the major benefits to associated keys is that the order doesn't matter anymore. Having this one feature order dependant whilst using the associated keys isn't correct in my view. On 20 March 2015 at 14:41, Rowan Collins wrote: > Alex Bowers wrote on 20/03/2015 13:40: > >> Still not sure how we can implement a range of strings. But since thats >> for a different feature, I'll leave that issue for now. >> > > I can't resist a quick answer: if you can define a key-based slice at all, > you can define it for both integer and string keys. Bear in mind the a:b > here isn't a range, it's just a pair of values specifying which items to > include in the slice. > > If the definition of a key-based slice is "all elements whose key > satisfies $key >= $a && $key <= $b", then you're just doing comparisons > between strings, which are defined as lexical order. So > $dictionary['elephant':'snake'] returns all elements with keys which sort > lexically between 'elephant' and 'snake', regardless of whether the array > is sorted. > > Alternatively, a key-based slice could look up the position in the array > of the two keys, and then perform a positional slice between those > positions, i.e. $array[$a:$b] == $array[ @ key_position($array, $a) : > key_position($array, $b) ]. I'm not sure that's particularly intuitive or > useful, but again, it has no problem with string keys. > > Regards, > -- > Rowan Collins > [IMSoP] > --001a11c37f9c1de9850511b9834d--