Why out of several str_replace() functions only the last one affects the string?
<p>I have set up a very simple code snippet:</p>

<pre><code>$string = 'Some random words. Some more random, very random words.';
$words = explode(" ", $string);

for ($i = 0; $i &lt; count($words); $i++) {
    $word = $words[$i];
    $words[$i] = str_replace(".", "!", $word);
    $words[$i] = str_replace(",", "?", $word);
}

print_r($words);
</code></pre>

<p>The output is this:</p>

<pre><code>Array
(
    [0] =&gt; Some
    [1] =&gt; random
    [2] =&gt; words.
    [3] =&gt; Some
    [4] =&gt; more
    [5] =&gt; random?
    [6] =&gt; very
    [7] =&gt; random
    [8] =&gt; words.
)
</code></pre>

<p>Why only the second <code>str_replace()</code> function affect the string? If I remove the second <code>str_replace()</code> the first one works perfectly. It's not about usage of <code>str_replace()</code> but I believe me doing something very very simply wrong.</p>

<p>By the way - I am aware of <code>preg_replace()</code> and passing an array to <code>str_replace()</code> but would like to hear about this particular situation :).</p>

<p><strong>EDIT:</strong>
Thank you all for blazing quick responses. I am in a shame for such an issue but it really didn't catch my eyes at first. Thanks everyone! I will accept the first correct answer by <strong>Mike Brant</strong>.</p>
