title: How do I structure data in php to get the correct json result?
body: <p>I am working in php and need to export a json document in the following format (below).  </p>
  
  <p>I know how to do the actual export with <code>file_put_contents($data_file, json_encode($json_array));</code> but I'm struggling with what format I need to have the $json_array in to achieve the desired results.</p>
  
  <p>I need the final json file to be formatted like this:</p>
  
  <pre><code>{
    "2016": [
        {
          "date": "2016/01/01",
          "close": 837
        },
        {
          "date": "2016/12/01",
          "close": 769
        }
      ],
    "2015": [
        {
          "date": "2015/01/01",
          "close": 637
        },
        {
          "date": "2015/12/01",
          "close": 669
        }
      ],
    "2014": [
        {
          "date": "2014/01/01",
          "close": 537
        },
        {
          "date": "2014/12/01",
          "close": 569
        }
      ]
  }
  </code></pre>
  
  <p>Is this accomplished by exporting an array with 3 keys, each containing a multidimensional array?  Or an array of objects of some type?</p>
  
  <p>Maybe I'm overthinking this, but I've been working this problem all day and have not been able to get the desired results.</p>
  
  <p>To me the structure looks like an array; with the (first) key of 2016 and a value of an array, but then what's inside that array?</p>