title: How to calculate cumulative sum in PHP?
body: <p>I want to calculate the sum and output a two columns table. But, the format is wrong. The numbers are all packed in one line.</p>
  
  <p><a href="https://i.stack.imgur.com/0wRqG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0wRqG.png" alt="Wrong table"></a></p>
  
  <pre><code> &lt;td&gt;
   &lt;?php
  for ($j = 1; $j &lt;= 10; $j++)
      {
          print "&lt;tr&gt;";
          print $j;
          print "&lt;/tr&gt;";
      }
  ?&gt;    
   &lt;/td&gt;
  
   &lt;td&gt;
   &lt;?php
  $sum = 0;
  for($i = 1; $i&lt;=10; $i++) 
  {
       print "&lt;tr&gt;";
       print $sum = $sum + $i;
       print "&lt;/tr&gt;";
  
  }
  ?&gt;    
   &lt;/td&gt;
  </code></pre>