title: PHP Foreach on MySQLi Result set
body: <p>I have this chunk of code which works on my local XAMPP testing server. The problem is, when pushed to the production server, it breaks. This isn't an issue with the database connection, and PHP/MySQL are both at 5.3 on the production server so it isn't the use of old versions of either. I'm thinking it's the use of the foreach loop instead of the more standard while loop; if it's that, why?</p>
  
  <pre><code>&lt;?php
     $res = $mysqli-&gt;query('DESCRIBE '.$table);
     $columnCount = 0;
     echo '&lt;ul&gt;';
     foreach($res as $field) {
       if(in_array($field["Field"], $sheetData[0])) {
        echo '&lt;li&gt;';
              //var_dump($field);
        echo $field['Field'].' - '.$field['Type'];
        echo "&lt;/li&gt;\r\n";
        $columnCount++;
      }
    }
    echo '&lt;/ul&gt;';
  ?&gt;
  </code></pre>
  
  <p>EDIT: To clarify, it breaks by not outputting anything at all; when inserting a simple echo statement inside the loop, it seems to not even execute it.</p>
  
  <p>EDIT2: I've added an answer below which goes into slightly more detail about what the problem here actually was and why this code does actually work under certain conditions.</p>