title: Multidimensional array in PHP with keys
body: <p>I making a script to monitorize data from some VPSs, which is being stored in a MySQL database.</p>
  
  <pre><code>$result = mysql_query("SELECT * FROM data");
  $data = array();
  while ($row = mysql_fetch_array($result)) {
      $data[] = array(
               'id' =&gt; $row['id'],
               'hostname' =&gt; $row['hostname'],
               'loadavrg' =&gt; $row['load average']
      );
  }
  </code></pre>
  
  <p>I would like to separase data by hostnames so I can read it like the following example:</p>
  
  <pre><code>foreach($data['sitename.com'] as $d)
      echo $d['loadavrg'];
  </code></pre>
  
  <p>I already tried with the following code (just for testing), but didn't work:</p>
  
  <pre><code>$result = mysql_query("SELECT * FROM data WHERE hostname='sitename.com'");
  $data = array();
  while ($row = mysql_fetch_array($result)) {
      $data[] = array(
          'sitename.com' =&gt; array(
              'id' =&gt; $row['id'],
              'loadavrg' =&gt; $row['load average']
          )
      );
  }
  </code></pre>
  
  <p>I'm just missing the right way and syntax to achieve it :X</p>