title: Unneccesary new line php
body: <p>I have a PHP code. The code is supposed to print the output followed by a new line.
  The code works fine but i have unneccesary new line at the end. There should be only one newline at the end, but my code prints several new lines. What could be the issue? Please help.</p>
  
  <pre><code>&lt;?php
    /* Read input from STDIN. Print your output to STDOUT*/
    $fp = fopen("php://stdin", "r");
    //Write code here
    $loop = 0;
    $n = 0; $arr = [];
    while(!feof($fp)) {
      $arr = []; $n = 0;
      if($loop == 0) {
        $total = fgets($fp);
      }
      else {
        if($loop%2 == 1) {
          $n = fgets($fp);
        }
        else {
          $arr = fgets($fp);
        }
      }
      if($loop &gt; 0 &amp;&amp; $loop%2 == 0) {
        $arr = explode(" ", $arr);
        $m = [];
        for($i = 0; $i &lt; 1&lt;&lt;10; $i++) {
          $m[$i] = -1;
        }
        $n = count($arr);
  
        $r = 0;
        for($i = 0; $i &lt; 1&lt;&lt;10; $i++) {
          $r = max($r, fd_sum($i, $m, $arr, $n));
        }
  
        echo $r."\n";
      }
  
      $loop++;
    }
    fclose($fp);
  
  ?&gt;
  
  &lt;?php
    function fd_sum($i, $m, $arr, $n) {
      if($i == 0) {
        return $m[$i] = 0;
      }
      else if($m[$i] != -1) {
        return $m[$i];
      }
      else {
          $rr = 0;
          for($j = 0; $j &lt; $n; $j++) {
            $num = (int)$arr[$j];
            $b = save($num);
            if(($i | $b) == $i) {
                $z = $i^save($num);
                $y = fd_sum($z, $m, $arr, $n);
                $v = ($y + $num);
              $rr = max($v, $rr);
            }
  
          }
          return $m[$i] = $rr;
      }
    }
  ?&gt;
  
  &lt;?php
    function save($nm)
    {
      $x = 0;
      for($i = 1; $nm/$i &gt; 0; $i *= 10) {
        $d = ($nm/$i) % 10;
        $x = $x | (1 &lt;&lt; $d);
      }
      return $x-1;
    }
  
  ?&gt;
  </code></pre>
  
  <p>My input is </p>
  
  <pre><code>3
  4
  3 5 7 2
  5
  121 3 333 23 4
  7
  32 42 52 62 72 82 92
  </code></pre>
  
  <p>My output is</p>
  
  <pre><code>17
  458
  92
  -
  -
  -
  -
  </code></pre>
  
  <p>The expected output is</p>
  
  <pre><code>17
  458
  92
  -
  </code></pre>
  
  <p><strong>Note</strong> : I have used '-' to indicate a new line</p>
  
  <p>What am i doing wrong? Please help.</p>