title: Fastest way to remove character from string at specific index?
body: <p>I previous removed charactors from a string by using:</p>
  
  <pre><code>$str[$position] = '';
  </code></pre>
  
  <p>I need to do this several times and in a loop:</p>
  
  <pre><code>while ($condition == true)
  {
       $str[$position++] = '';
       // My code
  }
  </code></pre>
  
  <p>The code worked perfectly and was very efficient, however, it no longer works now that I've upgraded to PHP 7.1.4.</p>
  
  <p>If I use:</p>
  
  <pre><code>while ($condition == true)
  {
       $str[$position++] = ' ';
       // My code
  }
  </code></pre>
  
  <p>It works, but I get unwanted spaces.</p>
  
  <p>I could make this work using, <code>substr_replace</code>, however, that would be extremely inefficient. What's the fastest and most efficient way to solve the problem and why doesn't it work with PHP 7.1.4?</p>
  
  <p>EDIT</p>
  
  <p>I fixed the code that stopped working after upgrading PHP by using <code>substr_replace</code>. At first it would appear <a href="https://stackoverflow.com/users/6631691/tcpeng">tcPeng</a> is correct in saying: </p>
  
  <blockquote>
    <p>if you assign a empty string to a string offset, a warning should be raised and the string shouldn't be modified</p>
  </blockquote>
  
  <p>because that is the exact problem I was having. However, elsewhere in my code, I have:</p>
  
  <pre><code>while (trim($file[$i]) !== 'default:')
      $file[$i++] = '';
  </code></pre>
  
  <p>Surely, that code should no longer work either. The strange thing is, it does work. Why does it work, and is there any point in me changing the code to use <code>substr_replace</code>?</p>
  
  <p>The only differences between the code I had to fix with <code>substr_replace</code> and the code that happens to still work, is the code I had to fix, the string was an element of an array and it was being output with <code>echo</code>. With the code that still works, I am saving it with <code>file_put_contents</code>.</p>