title: Display PHP array data into table cell with cell number
body: <p>I have an array from database </p>
  
  <pre><code>Array
  (
      [0] =&gt; stdClass Object
          (
              [cell] =&gt; 2
              [price] =&gt; 1543.65
          )
  
      [1] =&gt; stdClass Object
          (
              [cell] =&gt; 3
              [price] =&gt; 386.22
          )
  
  )
  </code></pre>
  
  <p>and A table </p>
  
  <pre><code>&lt;table&gt;
      &lt;tr&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;4&lt;/td&gt;
      &lt;td&gt;5&lt;/td&gt;
      &lt;td&gt;6&lt;/td&gt;
      &lt;td&gt;7&lt;/td&gt;
      &lt;td&gt;8&lt;/td&gt;
      &lt;td&gt;9&lt;/td&gt;
      &lt;td&gt;10&lt;/td&gt;
      &lt;td&gt;12&lt;/td&gt;
      &lt;td&gt;12&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
      &lt;?php
       print_r($sales);
       if(!empty($sales)) {
          foreach($sales as $sale) {
  
           if($sale-&gt;cell == 1) {echo "&lt;td&gt;".$sale-&gt;price."&lt;/td&gt;";} else { echo "&lt;td&gt;0&lt;/td&gt;"; }
           if($sale-&gt;cell == 2) {echo "&lt;td&gt;".$sale-&gt;price."&lt;/td&gt;";} else { echo "&lt;td&gt;0&lt;/td&gt;"; }
           ...
           if($sale-&gt;cell == 12) {echo "&lt;td&gt;".$sale-&gt;price."&lt;/td&gt;";} else { echo "&lt;td&gt;0&lt;/td&gt;"; }
  
          }
  
      } else {
      for($i=1; $i&lt;=12; $i++) {
          echo "&lt;td&gt;0&lt;/td&gt;";
      }
      }
      ?&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
  </code></pre>
  
  <p>I need to display price in same cell as it is in array. Now my problem is array size is not 12. Please help how can I display this on same cell as in <code>array['cell']</code>?</p>
  
  <p>I want to display it as: </p>
  
  <pre><code>&lt;tr&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;1543.65&lt;/td&gt;
      &lt;td&gt;386.22&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;/tr&gt;
  </code></pre>
  
  <p>Your help and time is appreciated.</p>