title: Large loop with performance problems
body: <p>I've got two large arrays, where second one is dependant on first one.</p>
  
  <p>Categories, about 40 rows, Items about 40.000 per Category.</p>
  
  <ol>
  <li>I need to go through every Category - get Category object.</li>
  <li>Get from database Items for Category.</li>
  <li>Compare Items if there share value of specific attribute</li>
  </ol>
  
  <p>using PHP 7.1 I'want to get without O(n)^n solution if possible.</p>
  
  <pre><code>
  private function removeOverlap()
  {
      $categories = $this-&gt;getCategories();
  
      foreach($categories as $category)
      {
          $items = $this-&gt;getItems($category);
  
          foreach($items as $item)
          {
              foreach($items as $sibling)
              {
                  if($item === $sibling) continue;
  
                  $this-&gt;fixOverlap($item, $sibling)
              }
          }
      }
  }
  
  </code></pre>
  
  <p>I'm looking for performance upgrade, because this takes literally forever.</p>