Re: Support negative indexes for arrays and strings
| From: | Stas Malyshev | Date: | Mon, 11 Jun 2012 19:13:47 +0000 |
| Subject: | Re: Support negative indexes for arrays and strings | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-60791@lists.php.net to get a copy of this message | ||
Hi!
>> Can be:
>> $var = 'abc';
>> echo $var[-1];
>
> This seems simple enough for a hard-coded -1, but...
>
> Would $var[-2] be strlen($var) - 2 and so on?
The main question is what happens with "foo"[-4] or ['x'][-2].
> And then one would expect some rather complex logic to compute -N for
> $var[-N]
I don't see much of complex logic here, but $a[2] = 'a' would create a
new array element if it does not exist, while $a[-2] can't. Not a big
issue, but somewhat inconsistent I guess.
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227