title: php preg_replace not working within foreach loop
body: <p>I have the following structure :</p>
  
  <pre><code>&lt;?php
    $i = 0;
    foreach ($users as $user) {
      $i++;
      $string = '&lt;span&gt;The number is $i&lt;/span&gt;';
      $string = preg_replace('/\&lt;span.*?\/&gt;$/e','',$string);
      echo $string;
    }
  ?&gt;
  </code></pre>
  
  <p>It appends the <code>$string</code> the number of times <code>foreach</code> loop iterate whereas i just want it to display one time as <code>The number is 4</code> at the end of the loop. <code>preg_replace</code> works if outside of the loop. How can i <code>echo</code> the output one time and delete rest. I need to do it within the loop and not outside it. </p>