Two dimensional associative array in PHP
<p>In my code I'm getting data (three columns) from a sql db and I want to store the rows in an associative PHP array. The array must be multi-dimensional because I want to use the row id from the database as a key so that i can fetch values like this:</p>

<blockquote>
  <p>$products["f84jjg"]["name"]</p>
  
  <p>$products["245"]["code"]</p>
</blockquote>

<p>I've tried using the following code but it doesn't work:</p>

<pre><code>while ($row = mysql_fetch_row($sqlresult))
{
    $products = array($row[0] =&gt; array(
         name =&gt; $row[1], 
         code =&gt; $row[2]
        )
    );
}
</code></pre>

<p>Also, how should I reference the key if it is taken from a variable? What I want to do is:</p>

<pre><code>$productName = $products[$thisProd]["name"];
</code></pre>

<p>Will this work?</p>
