title: PHP: preg_replace only first matching string in array
body: <p>I've started with preg_replace in PHP and I wonder how I can replace only first matching array key with a specified array value cause I set preg_replace number of changes parameter to '1' and it's changing more than one time anyways. I also splitted my string to single words and I'm examining them one by one:</p>
  
  <pre><code>&lt;?php
    $internal_message = 'Hey, this is awesome!';
  
    $words = array(
       '/wesome(\W|$)/' =&gt; 'wful',
       '/wful(\W|$)/' =&gt; 'wesome',
       '/^this(\W|$)/' =&gt; 'that',
       '/^that(\W|$)/' =&gt; 'this'
    );
  
    $splitted_message = preg_split("/[\s]+/", $internal_message);
    $words_num = count($splitted_message);
  
    for($i=0; $i&lt;$words_num; $i++) {
       $splitted_message[$i] = preg_replace(array_keys($words), array_values($words), $splitted_message[$i], 1);
    }
  
    $message = implode(" ", $splitted_message);
    echo $message;
  ?&gt;
  </code></pre>
  
  <p>I want this to be on output:</p>
  
  <blockquote>
    <p>Hey, that is awful</p>
  </blockquote>
  
  <p>(one suffix change, one word change and stops)</p>
  
  <p>Not this:</p>
  
  <blockquote>
    <p>Hey, this is awesome</p>
  </blockquote>
  
  <p>(two suffix changes, two word changes and back to original word &amp; suffix...)</p>
  
  <p>Maybe I can simplify this code? I also can't change order of the array keys and values cause there will be more suffixes and single words to change soon. I'm kinda newbie in php coding and I'll be thankful for any help ;></p>