title: Similarity algorithm advice, using two dimensional associative array
body: <p>The main goal of this algorithm is to find similar titles of news articles from different sources of web and group them, let's say above 55.55% similarity. </p>
  
  <p>My current approach of the algorithm consist of following steps:</p>
  
  <ul>
  <li>Feed data from MYSQL database into a two-dimensional array ex. <strong>$arrayOne</strong>.</li>
  <li>Make another copy of that array into ex. <strong>$arrayTwo</strong>.</li>
  <li>Create a clean array which will only contain similar titles and other content ex. <strong>$array_smlr</strong>.</li>
  <li>Loop, foreach <strong>$arrayOne</strong> <em>article_title</em> check for similarity with <strong>$arrayTwo</strong>   <em>article_title</em></li>
  <li>If similarity of between two titles is above 55% and if the article is not from the same news source (this way I don't check same articles from the same source) add it to <strong>$array_smlr</strong></li>
  <li>Sort the <strong>$array_smlr</strong> based on percentages of similarity, this way I end up grouping titles that are similar.</li>
  </ul>
  
  <p>Below is my code for the above tasks mentioned.</p>
  
  <pre><code>$result = mysqli_query($conn,"SELECT id_articles,article_img,article_title,LEFT(article_content , 200),psource, date_fetched FROM project.articles WHERE " . rtrim($values,' or') . " ORDER BY date_fetched DESC LIMIT 70");
  
  $arrayOne=array();
  $arrayTwo=array();
  
  while($row = mysqli_fetch_assoc($result)){
      $arrayOne[] = $row;
  }
  $arrayTwo = $arrayOne;
  $array_smlr=array();
  foreach ($arrayOne as $rowOne) {
      foreach($arrayTwo as $rowTwo){
          $compare = similar_text($rowOne['article_title'], $rowTwo['article_title'], $p);
          if ( round($p,2) &gt;= 55.50 and $rowOne['psource'] != $rowTwo['psource'] ){
              $data =  array('percentage' =&gt; round($p,2), 'article_title' =&gt; $rowTwo['article_title'], 'psource' =&gt; $rowTwo['psource'], 'id_articles' =&gt; $rowTwo['id_articles'], 'date_fetched' =&gt;$rowTwo['date_fetched']);
              $array_smlr[]=$data; 
          }
      }
  }
  array_multisort($array_smlr);
  foreach($array_smlr as $row3){
      echo $row3['percentage'] . $row3['article_title'] . $row3['psource'] . $row3['id_articles'] . $row3['date_fetched'] . "&lt;br&gt;&lt;br&gt;";
  }
  </code></pre>
  
  <p>This would work with limited functionality, only if I had two similar titles, but let's say if I had 3 similar titles, it would include duplicated rows of data in <strong>$array_smlr</strong>. </p>
  
  <p>I would appreciate if you have any suggestions on optimization of this algorithm in order to improve the performance.</p>
  
  <p>Thanks,</p>