title: Most efficient way to compare/match two large arrays?
body: <p>I am writing a very process-intensive function in PHP that needs to be as optimized as it can get for speed, as it can take up to 60 seconds to complete in extreme cases. This is my situation:</p>
  
  <p>I am trying to match an array of people to an XML list of jobs. The array of people have keywords that I have already analyzed, delimited by spaces. The jobs are from a large XML file.</p>
  
  <p>It's currently setup like this: </p>
  
  <pre><code>$matches = new array();
  foreach($people as $person){
      foreach($jobs as $job){
          foreach($person['keywords'] as $keyword){
              $count = substr_count($job-&gt;title, $keyword);
              if($count &gt; 0) $matches[$job-&gt;title] = $count;
          }
      }
  }
  </code></pre>
  
  <p>I do the keywords loop a few times with different categories. It does what I need it to do, but it feels very sloppy and the process can take a very, very long time depending on the number of people/jobs.</p>
  
  <p>Is there a more efficient, or faster, way of doing this?</p>