We all know (well the coders amongst us so anyway) that while we might be very fond of PHP, it does not do Arrays properly.

I could go into great detail, but basically there are historic (and no doubt design) reasons for the way in which PHP handles the most useful of data structures, and while often very handy, there are times when I long for the whole thing to just work!

Arrays in PHP are all __actually__ hashes, and are only treated as Arrays if they have numeric keys that begin from 0.

I just wasted 2 hours of my life having forgotten the last point of the above. I was unable to work out why two apparently identical arrays were rendered into very different JSON by json_encode(). Well, it turns out that all I had to do was marshall the Hash with numeric keys (that I think I could be forgiven for expecting to behave as an array) into a fresh array (staring from 0), and hey presto!

I hope that someone else who is fighting with this delightful little idiosyncrasy will benefit from my having laid out my pain and dumbness for all to see…

That is all.
.
EOF