Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85295 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39182 invoked from network); 20 Mar 2015 14:56:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Mar 2015 14:56:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.169 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.169 mail-wi0-f169.google.com Received: from [209.85.212.169] ([209.85.212.169:38713] helo=mail-wi0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 50/19-21731-2913C055 for ; Fri, 20 Mar 2015 09:41:22 -0500 Received: by wibgn9 with SMTP id gn9so16411212wib.1 for ; Fri, 20 Mar 2015 07:41:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=bufGiN4WYkFKxZMmUAaZiRfgCc6+cM7vbuo9jRxUjUo=; b=hovNr0g4SPDU7m1GBUEyas72QcbE2kOkFAB8rGZiVCNvHxOv7tvmZcUz2bwHL+v9dj OB9SgpmIHx0hXfO875pitBEpw8HxcHIaXCOf9i0F2P2KuXT5p+5KewQy6j1XwtzpRY86 qhRxW4T/YWuVlu7Tx8OpskMsu4D/LZauQFB8dp+HoESmnk5QUIATnfJzcIBg4Y84l8LU uVSdo9Hud9obgG/0ueRF+LU2JbeKkumYQqM9QNpijxtfkIXpgCBCvHXcsBc+7jDt0ZFI QDA/hbU8zf7mL6bxh2IyJ/x6DASjAuNMRsKOC4BPad+mK6bUj2mWIyN9i8d0KZpWnH0j bELA== X-Received: by 10.180.9.131 with SMTP id z3mr25148231wia.64.1426862479791; Fri, 20 Mar 2015 07:41:19 -0700 (PDT) Received: from [192.168.0.159] ([62.189.198.114]) by mx.google.com with ESMTPSA id r14sm3304844wiv.13.2015.03.20.07.41.18 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Mar 2015 07:41:19 -0700 (PDT) Message-ID: <550C317E.8020508@gmail.com> Date: Fri, 20 Mar 2015 14:41:02 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Alex Bowers CC: internals@lists.php.net 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> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RFC - Array slice syntactic sugar From: rowan.collins@gmail.com (Rowan Collins) 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]