title: Passing Array from Model to Controller to View in CodeIgniter
body: <p>I have a model that sends an error response to the controller in CodeIgniter that then is passed to the view which is just a JSON encoder. Here is the array from the model.  </p>
  
  <pre><code>return $posts[] = array('complete'=&gt;0,'error'=&gt;1003, 'message'=&gt;'Username already exists');
  </code></pre>
  
  <p>The issue I am having is that I need those square brackets after the $posts variable because sometimes I need an array of errors. However when I pass the single array to the view it encodes the JSON without the square brackets but when I have multiple arrays it includes the square brackets, I need the square brackets in the JSON every time. Here is the Controller...  </p>
  
  <pre><code>$data['data'] = $this-&gt;logins_model-&gt;signup($post_data);  
  $this-&gt;load-&gt;view('json', $data);  
  </code></pre>
  
  <p><strong>Here is the view...</strong>  </p>
  
  <pre><code>header('Content-type: application/json');  
  $response['response'] = $data;  
  echo json_encode($response); 
  </code></pre>
  
  <p><strong>I need the JSON response to look like this</strong>  </p>
  
  <pre><code>{
      "response": [
          {
              "complete": 0, 
              "error": 1003, 
              "message": "Username already exists"
          }
      ]
  }  
  </code></pre>
  
  <p><strong>NOT THIS!</strong>  </p>
  
  <pre><code>{
      "response": {
          "complete": 0, 
          "error": 1003, 
          "message": "Username already exists"
      }
  }
  </code></pre>