Req #65479 [Opn->Wfx]: Accessing key -1 should return last value of array
| From: | nikic@php.net | Date: | Mon, 19 Aug 2013 19:01:57 +0000 |
| Subject: | Req #65479 [Opn->Wfx]: Accessing key -1 should return last value of array | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-181008@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65479&edit=1
ID: 65479
Updated by: nikic@php.net
Reported by: jordandoyle133 at gmail dot com
Summary: Accessing key -1 should return last value of array
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: Arrays related
Operating System: All
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
This is not possible, because -1 is a valid array key. Consider:
echo [-1 => -1, 0, 1, 2][-1]; // int(-1)
Previous Comments:
------------------------------------------------------------------------
[2013-08-19 18:33:28] jordandoyle133 at gmail dot com
Description:
------------
Accessing minus keys should start from the end of the array much like the behavior
in Perl or Python
Test script:
---------------
<?php
echo [1, 2, 3][-1] . PHP_EOL;
echo [3, 2, 1][-2] . PHP_EOL;
echo ['foo', 'bar'][-1] . PHP_EOL;
Expected result:
----------------
3
2
bar
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65479&edit=1