Categories
arrays php

Negative index of array in PHP

I found some code that uses negative array indices. Then, I try to use it, nothing special happens. It behaves normally. I can retrieve all elements by using a standard foreach loop.

So, what is the purpose to use those negative indices? And when should I use it?

An array, in PHP, is actually just some kind of an ordered map : you can use integers (positive or negative), but also strings, as keys — and there will not be much of difference.