title: Array explode json
body: <p>I would like to generate json from form data. This is what i have:</p>
  
  <pre><code>&lt;?php
  $data = explode(',', $data);
  $accounts = [];
  
  foreach ($data as $split) {
       $split = explode(':', $split);
       $accounts['username'] = trim($split[0]);
       $accounts['password'] = $split[1];
  }
  
  var_dump(json_encode($accounts));
  </code></pre>
  
  <p>The problem is that it only does the last element in the loop. I know why it does that, but im overlooking something and cant get it right.. I want the json to be this;</p>
  
  <pre><code>{
    "Username": "username",
    "Password": "username"
  },
  {
    "Username": "username",
    "Password": "password"
  },
  </code></pre>
  
  <p>etc etc. What the best way to approach this? I'm prob not thinking right..</p>