Skip to content
  • home
  • portfolio
  • web design journal
  • blog
    • adventure
    • san diego
    • urbanity & architecture
    • projects
    • website design
Blog Web Dev PHP JSON Returned As Object Instead of Array

PHP JSON Returned As Object Instead of Array

By Forrest Smith - Drempd.com

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;

…etc…

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.

Posted on May 14, 2016August 26, 2022 in Web Dev
  • Adventure

    • adventure
    • gravelgrinding
    • hiking
    • running
  • The Built Environment

    • architecture
    • urbanity
  • Locations

    • san diego
    • portland
  • Freelance Life

    • freelancing
    • productivity
  • Web Dev

    • css
    • entrepreneurship
    • git
    • handlebars
    • html
    • inkscape
    • photoshop
    • php
    • sass
    • web design
    • web development
    • saphire

drempd | san diego, ca


home contact

adventures san diego urbanity and architecture projects stream website design

portfolio resume san diego web design freelance web designer

custom web design responsive web design website maintenance