title: Finding similar strings in array
body: <p>I need to harness <a href="http://php.net/similar_text" rel="nofollow"><code>similar_text()</code></a> for an array of values that look something like this:</p>
  
  <pre><code>$strings = ["lawyer" =&gt; 3, "business" =&gt; 3, "lawyers" =&gt; 1, "a" =&gt; 3];
  </code></pre>
  
  <p>What I'm trying to do is find the words what are practically the same, i.e. <code>lawyer</code> and <code>lawyers</code> in the above array, and add the counts for them together in a new array.</p>
  
  <p>So <code>lawyer</code> would be <code>4</code> as <code>lawyers</code> would be associated to the original string of <code>lawyer</code>.</p>
  
  <p>Keep in mind, this array will only ever be singular words and the length is unspecified, it could range from <code>1</code> to <code>&gt;99</code>.</p>
  
  <p>I had no idea where to start with this, so I gave it a crack with a foreach loop as you'll see below, but the intended output isn't as expected.</p>
  
  <pre><code>foreach ( $strings as $key_one =&gt; $count_one ) {
      foreach ( $strings as $key_two =&gt; $count_two ) {
          similar_text($key_two, $key_one, $percent);
          if ($percent &gt; 80) {
              if(!isset($counts[$key_one])) {
                  $counts[$key_one] = $count_one;
              } else {
                  $counts[$key_one] += $count_two;
              }
          }
      }
  }
  </code></pre>
  
  <p><sup><strong>Note:</strong> <em>The percent match is at <code>80</code> for this example (as the match for <code>lawyer</code> &amp; <code>lawyers</code> is <code>~92%</code>)</em></sup></p>
  
  <p>Which ends up giving me something similar to the following:</p>
  
  <pre><code>Array
  (
      [lawyer] =&gt; 4
      [business] =&gt; 3
      [a] =&gt; 3
      [lawyers] =&gt; 2
  )
  </code></pre>
  
  <p>Where I require it to be:</p>
  
  <pre><code>Array
  (
      [lawyer] =&gt; 4
      [business] =&gt; 3
      [a] =&gt; 3
  )
  </code></pre>
  
  <p><sup><em>Notice how i require it to practically remove <code>lawyers</code> and add the count to <code>lawyer</code>.</em></sup></p>