title: Creating a dynamic grid of images in PHP
body: <p>As part of a project I need to create a dynamic grid of images. This grid will consist of randomly placed images with empty spaces in between. For example:</p>
  
  <pre><code>------------------
  |Image|Blank|Blank|
  |Blank|Image|Image|
  |Blank|Image|Blank|
  ------------------
  </code></pre>
  
  <p>But I'm not sure whats the best way to do this? My idea is two nested for loops e.g.:</p>
  
  <pre><code>for ($r = 0; $r &lt;= $rows; $r++)
       for ($c = 0; $c &lt;= $cols; $c++)
           if(isset($data[$r][$c]['Image'])
               echo $data[$r][$c]['Image'];
  </code></pre>
  
  <p>And the data would be in the form:</p>
  
  <p><code>$data[row][col][image]</code></p>
  
  <p>With <code>row</code> and <code>col</code> being generated with the PHP <code>rand</code> function.</p>
  
  <p>Is this the best way to do this. Or have I overlooked something?</p>
  
  <p>Additionally with this set up how would I update <code>$data[row][col][image]</code> when the images are updated?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>The output of the grid will look like this:</p>
  
  <pre><code>&lt;div class="container"&gt;
      &lt;div class="RowWrapper&gt;
           &lt;div class="cell"&gt;Image&lt;/div&gt;
           &lt;div class="cell"&gt;&lt;/div&gt;
      &lt;/div&gt;
       &lt;div class="RowWrapper&gt;
           &lt;div class="cell"&gt;&lt;/div&gt;
           &lt;div class="cell"&gt;Image&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Thanks. </p>