title: how to json encode correctly in codeigniter
body: <p>i wanted to make the output look like this</p>
  
  <pre><code>[{"0":"1.1","1":"KAS &amp; BANK","2":"kosong"},
  {"0":"1.1","1":"KAS &amp; BANK","2":"kosong"},
  {"0":"1.1","1":"KAS &amp; BANK","2":"kosong"}]
  </code></pre>
  
  <p>but i really messed up with the code and the output 
  this is my controller </p>
  
  <p><code>public function coa($id){
          $data['listcoa'] = $this-&gt;easyway_model-&gt;getCoa($id);
          $this-&gt;load-&gt;view('perusahaan_coa', $data);
      }</code></p>
  
  <p>and this is my model</p>
  
  <pre><code>    public function getCoa($id) 
  {
      $query = $this-&gt;db-&gt;select('*')
            -&gt;from('tb_coa')
            -&gt;where('id_perusahaan', $id)
            -&gt;get();
      return $query;
  }
  </code></pre>
  
  <p>how should i call it in my view? so far i'm using foreach like this but the output really messed up</p>
  
  <pre><code>foreach($listcoa-&gt;result() as $list){
  $cabang[] = $list-&gt;no_account;
  $cabang[] = $list-&gt;deskripsi_coa;
  $cabang[] = $list-&gt;tipe_akun;
  $json = json_encode($cabang, JSON_FORCE_OBJECT); 
  echo $json; }
  </code></pre>
  
  <p>this is the output i get so far</p>
  
  <pre><code>{"0":"1.1","1":"KAS &amp; BANK","2":"kosong"}{"0":"1.1","1":"KAS &amp; BANK","2":"kosong","3":"1.1.001","4":"KAS","5":"kosong"}{"0":"1.1","1":"KAS &amp; BANK","2":"kosong","3":"1.1.001","4":"KAS","5":"kosong","6":"1.1.002","7":"MANDIRI","8":"kosong"}
  </code></pre>
  
  <p>without the comma and the index of array keep increasing .</p>