title: PHP Array Manipulation, Invalid Argument Supplied for foreach()
body: <p>I have an MVC structure set up in codeigniter in PHP.  However, for some reason, my model results do not like being foreached over, giving me; <code>Invalid argument supplied for foreach()</code>.  Here is the rough code of my model:</p>
  
  <pre><code>class some_model extends CI_Model
  {
      function __construct()
      {
          // Call the Model constructor
          $this-&gt;load-&gt;database();
      }
  
      function some_func()
      {
         //Prepare return
         $return = array();
  
         //Do query
         $query = $this-&gt;db-&gt;query('SELECT tbl.* from tbl');
  
         //Get array of values
         $result = $query-&gt;result_array();
  
         foreach($result as $row)
         {
             $return[] = array(
  
                 'a'                    =&gt; $row['a'],
                 'b'                    =&gt; $row['b'],
                 'c'                    =&gt; $row['c']
             );
         }
  
      return $return;
  }
  </code></pre>
  
  <p>And the controller:</p>
  
  <pre><code>$this-&gt;load-&gt;model('some_model');
  $stuff = $this-&gt;some_model-&gt;some_func();
  
  foreach($stuff as $row)
  {
     //Do something
  }
  </code></pre>
  
  <p>But I always get an error at the foreach loop in the controller.  Does anyone have an idea as to why this might be happening?  I have checked, and PHP does see <code>$stuff</code> as an array (<code>is_array($stuff)</code> returns true), so I have no idea what might be happening.  I do know that the foreach loop in the model is not the problem, as it does not give me any errors, only the one in the controller does. Any tips would be appreciated. Thanks beforehand!</p>