Re: Support negative indexes for arrays and strings
| From: | Lester Caine | Date: | Sat, 01 Sep 2012 12:07:21 +0000 |
| Subject: | Re: Support negative indexes for arrays and strings | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62632@lists.php.net to get a copy of this message | ||
Lester Caine wrote:
Sherif Ramadan wrote:OK ... got back form the weekly chore of shopping, and was thinking about what I had said :) "Different means of identifying position in the array"? I was probably thinking more along the lines of $numbers[-1] is a perfectly valid key on that array, so there is no way that it can be redefined otherwise. It would have to be something completely different such as $numbers[(-1)] to differentiate from the normal use of a key in the array ... and I would have to object strongly to adding that since it is different to other methods. The problem here was accepting that [-1] works differently on a string, and now we are seeing the consequences? It is only valid on a string and so this discussion needs a big brick wall between strings and 'collection arrays' ? People who think they need a position based indexing obviously need educating in the use of the array_slice and the other functions that seem to go with that, but I can see that this method of handling array indexes ( rather than keys ) COULD benefit from a tidy up. As has been discussed in general on the whole array API? -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.ukI can't understand what you mean by "Different means of identifying position in the array"? If you mean a way to access an array's element by its position in the array then yes, we already have that. It's called array_slice() seehttp://php.net/array-slice which allows you to access elements in the array by their offset and that includes using a negative offset. The key and the offset are two completely different things.Never had to use it ;) But then there is a heck of a lot of stuff I've never even looked at. But it does blow this thread - when referring to collection arrays - out of the water? The problem I see is people trying to apply 'string' rules in the wrong way ... and I find that string handling works fine for me as it currently works but we probably just need to STOP people trying to apply the same rules to something that is totally different? And I though that 'string' -ve indexes had been sorted?