Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85338 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38430 invoked from network); 20 Mar 2015 21:38:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Mar 2015 21:38:16 -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.169 as permitted sender) X-PHP-List-Original-Sender: bowersbros@gmail.com X-Host-Fingerprint: 209.85.212.169 mail-wi0-f169.google.com Received: from [209.85.212.169] ([209.85.212.169:34680] helo=mail-wi0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A2/1D-64120-8439C055 for ; Fri, 20 Mar 2015 16:38:16 -0500 Received: by wibg7 with SMTP id g7so2900196wib.1 for ; Fri, 20 Mar 2015 14:38:13 -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=sbF7v7EytOdVoHts2x0eAXzB/V9OjKUsQEJlfG6XhMs=; b=pfp3ZyOElOMM1WRDRSVOHfQAackRa0LCQilIvZzxJBhwWvNaS7uiv07dSqJyzHuqzo F/Y/Igx2JJMrdmG/OSPSY8LZicWb76v3K+CYiULfCQxqbfPQXXgvQizDIWYnfzT18k9Z 2Ih3U/SymW8gxpKSavnN8iBn6cKtjTXNTKFWKW15vUV8EW50zJLhYJ6W/GKyjzhx6BkY J+ab1R8D31HLBMS+kzQTGRrPypWVEfQBapTEMwJlOv+7WivWAm0KGJ6Bi+QtrPpgbsdK GOEx1e5hyFVsBtGe1GNRYRWLlnp6lct1ykz7LIJ7lm6iu4N8dbaTbVPVsrc9vuvfHWhc 7Xbg== MIME-Version: 1.0 X-Received: by 10.180.211.144 with SMTP id nc16mr28395008wic.82.1426887492944; Fri, 20 Mar 2015 14:38:12 -0700 (PDT) Received: by 10.28.62.84 with HTTP; Fri, 20 Mar 2015 14:38:12 -0700 (PDT) In-Reply-To: <550C90EF.7080404@gmx.de> References: <550B5A81.1090706@gmail.com> <550C8879.70002@gmail.com> <550C90EF.7080404@gmx.de> Date: Fri, 20 Mar 2015 21:38:12 +0000 Message-ID: To: Christoph Becker Cc: Stanislav Malyshev , PHP Internals Content-Type: multipart/alternative; boundary=001a11c2689026cc980511bf22af Subject: Re: [PHP-DEV] RFC - Array slice syntactic sugar From: bowersbros@gmail.com (Alex Bowers) --001a11c2689026cc980511bf22af Content-Type: text/plain; charset=UTF-8 > > // alternative old > foreach(array_slice($results, 0, 9) as $result) { > echo $result . "\n"; // 1 2 3 4 5 6 7 8 9 > } > Not so bad, in my opinion. To be the same, your example would have to be: // alternative old foreach(array_slice($results, 0, 9, true) as $result) { echo $result . "\n"; // 1 2 3 4 5 6 7 8 9 } since this will preserve the array keys. This was a quick off the top of my head example; there is also the benefit of overwriting multiple array items with a single line $array[*1:4] = [1,2,3,4]; // Sets array items 1 through 4 to be the values (and keys if provided), of the array assigned. $array[*1:] = [1,2,3,4]; // Sets array items 1 to the end to be values (and keys if provided), of the array assigned. This will also wipe out any additional information to the end of the array. Keeping anything before the first item, but extending until the end. This would be similar to array_replace, however that works from keys, not positions. --001a11c2689026cc980511bf22af--