 <p>If you want to cycle through the <code>$results</code> array, you should write </p> <p><code>foreach ($results as $key=&gt;$value)</code> </p> <p>rather than </p> <p><code>foreach ($results[0] as $key=&gt;$value)</code> </p> <p>unless <code>$results[0]</code> itself is an array, in which case <code>$results</code> would be a matrix (array of arrays).</p>