title: Best practice looping through huge arrays
body: <p>I have two huge arrays:</p>
  
  <ul>
  <li>array A has 4900 items (each item is a small array)</li>
  <li>array B has 700 items (also each item is a small array)</li>
  </ul>
  
  <p>So basically thees are my arrays:</p>
  
  <pre><code>A = array (
      [0] =&gt; array(
          "name" =&gt; "KE-KE IMPEX ",
          "email" =&gt; "someemai@gmail.com",
          "kezbCompany" =&gt; "Fragrance",
          "startDate" =&gt; "2013-03-25 00:00:00",
          "endDate" =&gt; "2014-03-25 00:00:00",
          "companyBase" =&gt; "06 20 232 2534"
      )
      ...
      [4900] =&gt; array(
          "name" =&gt; "Jane Doe",
          "email" =&gt; "zzer@sad.com",
          "kezbCompany" =&gt; "sadsad",
          "startDate" =&gt; "2013-03-25 00:00:00",
          "endDate" =&gt; "2014-03-25 00:00:00",
          "companyBase" =&gt; "06 20 232 2534"
      )
  )
  
  B = array (
      [0] =&gt; array(
          "name" =&gt; "KE-KE IMPEX 46554 sda",
          "email" =&gt; "xxx@gmail.com",
          "kezbCompany" =&gt; "546wer",
          "startDate" =&gt; "2013-03-25 00:00:00",
          "endDate" =&gt; "2014-03-25 00:00:00",
          "companyBase" =&gt; "06 20 232 2534"
      )
      ...
      [700] =&gt; array(
          "name" =&gt; "45 Jane Doe",
          "email" =&gt; "kekeimpex@gmail.com",
          "kezbCompany" =&gt; "asd",
          "startDate" =&gt; "2013-03-25 00:00:00"        
      )
  )
  </code></pre>
  
  <p>The small items look like this for example (booth in A and in B):</p>
  
  <pre><code>array(
    'name' =&gt; 'John Doe',
    'email' =&gt; 'john@doe.com'
  )
  </code></pre>
  
  <p>So what I need to do is: <strong>check which small array has the same name.</strong></p>
  
  <p><strong>But please keep in mind that most of the time the two small arrays wont be the same in structure.</strong></p>
  
  <p>So for example maybe their email are different. Right now, if I loop through the A first and inside that I loop through the B it takes a whole lot of time.</p>
  
  <p>This is my current code:</p>
  
  <pre><code>$szData = file_get_contents('szData.txt');
  $kData = file_get_contents('kData.txt');
  
  $A = json_decode($szData);
  $B = json_decode($kData);
  
  $foundNr = 0;
  
  foreach ($A as $key =&gt; $sz)
  {
      $cName = $sz-&gt;companyName;
  
      foreach ($B as $index =&gt; $k)
      {
          $pattern = '/^(.*)+('.$cName.')/i';
  
          echo "SzSor: " . $key . " --- Ksor: " . $index . "&lt;/br&gt;";
  
          if (preg_match($pattern, $k-&gt;companyName))
          {
              $founData[] = $k-&gt;companyName;
  
              ++$foundNr;
          }
      }
  }
  </code></pre>
  
  <p>Any ideas?</p>