title: Output two lines separately to the console in PHP
body: <p>I have written this small PHP script which counts from 0 to 9 while also showing the sum of the counted numbers.</p>
  
  <pre><code>&lt;?php
  $sum = 0;
  $line = '';
  for ($i=0; $i &lt; 10; $i++) {
      $sum += $i;
      echo str_repeat(chr(8), strlen($line)); // cleaning the line
      $line = "Counter: {$i} | Total: {$sum}";
      echo $line; // Outputing the new line
      sleep(1);
  }
  echo "\n";
  </code></pre>
  
  <p>As you see, on each iteration, I am cleaning up the line (<code>8</code> is the ASCII code for <code>backspace</code>) and showing the new text in the same line.</p>
  
  <p>This works fine, but now I want to show the Count and the Total in two different lines and animate the two lines in the same way that I did with one line. So I tried this code:</p>
  
  <pre><code>&lt;?php
  $sum = 0;
  $line = '';
  for ($i=0; $i &lt; 10; $i++) {
      $sum += $i;
      echo str_repeat(chr(8), strlen($line)); // cleaning the line
      $line = "Counter: {$i}\nTotal: {$sum}";
      echo $line; // Outputing the new line
      sleep(1);
  }
  echo "\n";
  </code></pre>
  
  <p>The issue here is that <code>backspace</code> stops at the <code>\n</code> character and so it deletes the second line but leaves the first line as it is which gives the following output:</p>
  
  <pre><code>Counter: 0
  Counter: 1
  Counter: 2
  Counter: 3
  Counter: 4
  Counter: 5
  Counter: 6
  Counter: 7
  Counter: 8
  Counter: 9
  Total: 45
  </code></pre>
  
  <p>Is there a proper way to solve this ?</p>
  
  <p>Thanks</p>