PHP JSON Returned As Object Instead of Array

By Forrest Smith -

I was returning, what I thought was an array from PHP, but it kept returning it as a json object, so I had something like:

$listItem[0][0] = “Jan 1”;
$listItem[0][1] = 100;

$listItem[1][0] = “Jan 2”;
$listItem[1][1] = 120;

$listItem[2][0] = “Jan 2”;
$listItem[2][1] = 120;


This would return in javascript those an array, but the index for each set was actually an object.  What was going on was apparently my ordered sequence (0,1,2,…) was actually missing a number in there somehow, and that was turning it into an object instead of an array.  Apparently the array values need to start with 0 and can’t skip any numbers for it to be returned as a numerical array.