title: Need help setting up json array
body: <p>A database query returns several rows which I loop through as follows:</p>
  
  <pre><code>    foreach ($query-&gt;result() as $row) {
  
          $data[$row-&gt;post_id]['post_id']         = $row-&gt;post_id;
          $data[$row-&gt;post_id]['post_type']       = $row-&gt;post_type;
          $data[$row-&gt;post_id]['post_text']       = $row-&gt;post_text;
      }
  </code></pre>
  
  <p>If I <code>json_encode</code> the resulting array (<code>$a['stream']</code>) I get </p>
  
  <pre><code>{
      "stream": {
          "1029": {
              "post_id": "1029",
              "post_type": "1",
              "post_text": "bla1",
          },
          "1029": {
              "post_id": "1030",
              "post_type": "3",
              "post_text": "bla2",
          },
          "1029": {
              "post_id": "1031",
              "post_type": "2",
              "post_text": "bla3",            
          }
      }
  }
  </code></pre>
  
  <p>But the <code>json</code> should actually look like this:</p>
  
  <pre><code>{
      "stream": {
          "posts": [{
              "post_id": "1029",
              "post_type": "1",
              "post_text": "bla1",
          },
          {
              "post_id": "1030",
              "post_type": "3",
              "post_text": "bla2",
          },
          {
              "post_id": "1031",
              "post_type": "2",
              "post_text": "bla3",            
          }]
      }
  }
  </code></pre>
  
  <p>How should I build my array to get this <code>json</code> right?</p>