title: PHP array that outputs field names and values as variables
body: <p>I am struggling a little bit with a tricky PHP array. I am trying to retrieve data from a database (a single row) and I want to plug this data in a bunch of dynamically generated fields on the page (PHP).</p>
  
  <p>My DB is organised as follows</p>
  
  <pre><code> ____________________________
  | cats | dogs | birds | cows |
  _____________________________   
  |  30  |  40  |  22   |  34  |
  ______________________________
  </code></pre>
  
  <p>I would like to build an array like this:</p>
  
  <pre><code>array(
         $cats =&gt; $cats_value
         $dogs =&gt; $dogs_value
         etc...
         )
  </code></pre>
  
  <p><strong>Importantly</strong>: I want the array to ouput variables, where in the above example $cats outputs "cats" and $cats_value outputs "30". I am guessing once this is done that I can use the variable names directly, so I won't have to go nuts trying to pull them out of the array...</p>
  
  <p>I have tried to put various bits of code but have failed miserably (i.e. nothing to show/embarrass myself with on here.)</p>
  
  <p>Any help would be much appreciated.</p>