Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73737 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9425 invoked from network); 18 Apr 2014 01:48:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Apr 2014 01:48:40 -0000 Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.182 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.128.182 mail-ve0-f182.google.com Received: from [209.85.128.182] ([209.85.128.182:53256] helo=mail-ve0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C8/31-00835-77480535 for ; Thu, 17 Apr 2014 21:48:39 -0400 Received: by mail-ve0-f182.google.com with SMTP id jw12so1808144veb.27 for ; Thu, 17 Apr 2014 18:48:36 -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=g9RgiyYDuNbg1WIkOQo2iJbXbi9U1vKR5yzTOZBQRIY=; b=kSi/VXtVFo8tGWmoQqZ3J3ZYR301QoCs8KwPAwsKiowOQOPvI521kOWW3v0/cc92qG ADirgPOLMvDly5LD+dmdQRRauQGeZfX9NS+UfxAKWQ/qEAQJTyr9qrlf6XDf8z/vRTHq ZrX7aFcbYcSa8Uo/hhr8ihq69KCRqKpAkS3h5Kra8gUy2qL/1kuZerKsdCSA3aMS7bMt Re4a86xXRPji9l8qGCMxsWoLZBl4XavCR601hxaHGfEzGdR6NI6iux3l/xplxOHV3Xn0 yEXJ32UJNbh4Zm0uWXf9wIMAPss2CWYXrKB/0VJFdyvR5ikhyQZiFyFpGkU/hXB5YNwi 5CqA== MIME-Version: 1.0 X-Received: by 10.58.96.36 with SMTP id dp4mr10610442veb.21.1397785716577; Thu, 17 Apr 2014 18:48:36 -0700 (PDT) Received: by 10.58.133.84 with HTTP; Thu, 17 Apr 2014 18:48:36 -0700 (PDT) In-Reply-To: References: Date: Fri, 18 Apr 2014 09:48:36 +0800 Message-ID: To: Levi Morrison Cc: PHP Internals Content-Type: multipart/alternative; boundary=089e013a26e61bf20404f74759a1 Subject: Re: [PHP-DEV] [pr-645] Add offset to reset() and end() From: tjerk.meesters@gmail.com (Tjerk Meesters) --089e013a26e61bf20404f74759a1 Content-Type: text/plain; charset=UTF-8 Hi Levi, On Fri, Apr 18, 2014 at 9:17 AM, Levi Morrison wrote: > On Thu, Apr 17, 2014 at 6:39 PM, Tjerk Meesters wrote: > >> Hi, >> >> I've added a PR that satisfies #31375. >> >> https://github.com/php/php-src/pull/645 >> >> It adds a second optional argument to reset() and end() to specify the >> number of elements that should be skipped (forward or backward). >> >> Currently, negative offsets are ignored. Should we raise a notice for such >> cases? Something like: >> >> "Negative offsets are not supported." >> >> Any feedback is welcome. Thanks! >> > > Do you have a specific use-case for these changes? > Surely you must have seen the feature request on bugs.php.net ;-) One example could be, traverse array but skip the first N elements: $array = [1, 2, 3]; for (reset($array, 1); $current = each($array); ) { var_dump($current['value']); } // output: int(2) int(3) Or, get second last element: $second_last = end($array, 1); // int(2) -- -- Tjerk --089e013a26e61bf20404f74759a1--