title: PHP: How to replace values in a string sequentially?
body: <p>I'm currently using PHP's str_replace to replace a particular value with another, in a loop.</p>
  
  <p>The problem is, str_replace will replace ALL of the instances of the first value, with the second value, rather than replacing them sequentially.  For example:</p>
  
  <pre><code>$replacements = array('A', 'one', 'some');
  $str = "The quick brown fox jumps over the lazy dog and runs to the forest.";
  foreach($replacements as $replace){
      $str = str_replace('the', $replace, $str);
  }
  </code></pre>
  
  <p>this will ultimately return:</p>
  
  <p>"A quick brown fox jumps over A lazy dog and runs to A forest."</p>
  
  <p>rather than what I want which would be:</p>
  
  <p>"A quick brown fox jumps over one lazy dog and runs to some forest."</p>
  
  <p>What would be the most efficient way of doing this?  I thought I could use preg_replace but I'm mediocre with regex.</p>