title: Creating 2-D matrix in php
body: <p>The thing is I have to create a 2D matrix in php where each row and column must have a key. I tried to do this but what happens is that a 2-D array is created which does not resemble a matrix. I used the following code:</p>
  
  <p><code>
  $x=$row['start_id'];<br/>
  $y=$row['dest_id'];<br/>
  $d=$row['distance'];<br/>
  $this->map[$x][$y]=$d;
  </code></p>
  
  <p>Here map is the intended matrix. The intention of this code is to create an adjacency matrix and then fill the unset cells with maximum distance. $x, $y and $d in above code are derived from result of a mysql query.</p>
  
  <p>Sample Output:</p>
  
  <pre><code>Array (
      [10010012] =&gt; Array ( 
          [10010013] =&gt; 2
          [10010016] =&gt; 8 
      )
      [10010016] =&gt; Array ( 
          [10010015] =&gt; 5 
      )
      [10010013] =&gt; Array ( 
          [10010014] =&gt; 7 
          [10010016] =&gt; 3
      )
      [10010014] =&gt; Array ( 
          [10010015] =&gt; 2 
      )
  )
  </code></pre>
  
  <p></p>
  
  <p>Now the problem is that I am not able to fill the empty cells
   <br>e.g. row key =>[10010012] and column key=>[10010015] (Not able to set value)</p>
  
  <p>Any help is appreciated. If possible also mention how to traverse through such matrices.</p>
  
  <p>I am a relative beginner and have tried my best to explain my problem. However if you find any shortcomings please point them out.</p>
  
  <p>Edit: The matrix is not a square one.</p>