title: Editing a poorly formatted JSON string in PHP
body: <p>I have a site which I used JSON to save some data.</p>
  
  <p>Here is how it saves data</p>
  
  <pre><code>{"1":{"english":{"grade":"7","time":"79"},"physics":{"grade":"3","time":"48"}}}
  </code></pre>
  
  <p><strong>Note:</strong> I know this is a poor way of doing it but I did it when I was not so vast!</p>
  
  <p>The <code>1</code> is the <code>user_id</code> which changes according to the id of the user that takes an exam on the platform. The <code>english</code>, <code>physics</code> are the subjects this user took.</p>
  
  <p>The maximum number of exam a user can take at a time is for so the <code>json</code> string will look like <code>{"1":{"english":{"grade":"7","time":"79"},"physics":{"grade":"3","time":"48"},"maths":{"grade":"7","time":"79"},"chemistry":{"grade":"3","time":"48"}}}</code></p>
  
  <p>First I think this is the best way to save the result as a <code>JSON</code> string</p>
  
  <pre><code>[{"subject":"english","grade":"7","time":"79"}, {"subject":"physics", "grade":"3","time":"48"}}]
  </code></pre>
  
  <p>My problem is that I want to use PHP to work on the former on. I have done some few stripping of the string and I'm left with this <code>{"english":{"grade":"7","time":"79"},"physics":{"grade":"3","time":"48"}}</code></p>
  
  <p>I tried this chunk</p>
  
  <pre><code>$JSONResult = json_decode($aScore-&gt;result);
  foreach ($JSONResult as $subjectKey =&gt; $aSubject)
  {
      foreach ($aSubject as $theResult)
      {
          $userResult = '
          Subject: **This is what I've not been able to get**
          Grade: '.$theResult-&gt;grade.'
          Time: '.$theResult-&gt;time.'
          ';
      }
  }
  </code></pre>
  
  <p>I tried <code>$aSubject-&gt;subjectKey</code> to get the associative key value from the first <code>foreach</code> statement but it did not work</p>
  
  <p>Any help?</p>
  
  <p><strong>Added: Please leave comments about the way the <code>JSON</code> string was stored. I'd love to learn.</strong></p>