title: Append data to JSON array using PHP
body: <p>I need to append a new object to a JSON array using PHP.</p>
  
  <p>The JSON:</p>
  
  <pre><code>{
     "maxSize":"3000",
     "thumbSize":"800",
     "loginHistory":[
     {
        "time": "1411053987",      
        "location":"example-city"
     },
     {
        "time": "1411053988",      
        "location":"example-city-2"
     }
  ]}
  </code></pre>
  
  <p>The PHP so far:</p>
  
  <pre><code>$accountData = json_decode(file_get_contents("data.json"));
  $newLoginHistory['time'] = "1411053989";
  $newLoginHistory['location'] = "example-city-3";
  array_push($accountData['loginHistory'],$newLoginHistory);
  file_put_contents("data.json", json_encode($accountData));
  </code></pre>
  
  <p>I keep getting 'null' as the output for the "loginHistory" object upon saving the JSON file.</p>