title: How to make the function work for pair words?
body: <p>My function now only works with one word. For example, I have words in an associative array. And my function replaces the array key with its value in the text. And the function to keep the words in the lower case, but when you replace words it will return the incoming word register that is written on the text. Now the function can not work with pairs of words to replace pairs of words with other pairs of words.</p>
  
  <h2>Example:</h2>
  
  <pre><code>// Function:
  
  function replaceKeyToValue($request, $dict){
      $response = preg_replace_callback("/\pL+/u", function ($m) use ($dict) {
          $word = mb_strtolower($m[0]);
          if (isset($dict[$word])) {
              $repl = $dict[$word];
              // Check for some common ways of upper/lower case
              // 1. all lower case
              if ($word === $m[0]) return $repl;
              // 2. all upper case
              if (mb_strtoupper($word) === $m[0]) return mb_strtoupper($repl);
              // 3. Only first letters are upper case
              if (mb_convert_case($word,  MB_CASE_TITLE) === $m[0]) return mb_convert_case($repl,  MB_CASE_TITLE);
              // Otherwise: check each character whether it should be upper or lower case
              for ($i = 0, $len = mb_strlen($word); $i &lt; $len; ++$i) {
                  $mixed[] = mb_substr($word, $i, 1) === mb_substr($m[0], $i, 1) 
                      ? mb_substr($repl, $i, 1)
                      : mb_strtoupper(mb_substr($repl, $i, 1));
              }
              return implode("", $mixed);
          }
          return $m[0]; // Nothing changes
      }, $request);
      return $response;
   }
  
      // Example associative array
  
      $dict = array
      (
        "make"=&gt;"take",
        "cool"=&gt;"pool",
        "узбек"=&gt;"ӯзбек",
      );
  
      $text = 'Make COOL узБЕК';
  
      echo replaceKeyToValue($text, $dict);
  </code></pre>
  
  <h3>Output:</h3>
  
  <pre><code>Take POOL ӯзБЕК
  </code></pre>
  
  <p>How will the function be redone so that it can also pair words into pair words?</p>
  
  <h3>Example array with pairs words:</h3>
  
  <pre><code>$array = array
  (
    "take pool" =&gt; "pool take", 
    "get book" =&gt; "set word", 
    "узбек точик" =&gt; "ӯзбек тоҷик"
  );
  
  $example_text = "Take POOL Get BooK УзБеК ТоЧИК";
  </code></pre>