Loop through entries taking far too long to finish I am attempting to loop through my "journalEntries" in order to find duplicates. For some reason, it is taking a very long time to finish and return a response to me. Last time I tested it, it took 12 seconds to finish.

$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;section = 'journalArticles';
$criteria-&gt;limit = 10;
$copies = array();

for($a = 0; $a &lt; count($criteria); $a++) {
  for($b = $a + 1; $b &lt; count($criteria); $b++) {
    if($criteria[$a]-&gt;title === $criteria[$b]-&gt;title) {
      array_push($copies, $criteria[$a]-&gt;title);
    }
  }
}

$this-&gt;returnJson($copies);


I think it is something I am doing incorrectly within the two for loops. As you can see, I limit the amount of articles to only 10, so something seriously funky must be going on. Any help?
Something like this should work and be faster.

$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;section = 'journalArticles';
$criteria-&gt;limit = 10;
$entries = $criteria-&gt;find();

$titles = array();
$copies = array();

foreach ($entries as $entry)
{
    $titles[] = $entry-&gt;title;
}

foreach (array_count_values($titles) as $val =&gt; $count)
{
    if ($count &gt; 1)
    {
        $copies[] = $val;
    }
}

$this-&gt;returnJson($copies);