title: Is there a faster way than array_diff in PHP
body: <p>I have a set of numbers from MySQL within the range 1000 0000 (8 digits) to  9 999 999 999 (10 digits). It's supposed to be consecutive, but there are missing numbers. I need to know which numbers are missing.</p>
  
  <p>The range is huge. At first I was going to use PHP to do this:</p>
  
  <pre><code>//MySqli Select Query
  $results = $mysqli-&gt;query("SELECT `OCLC Number` FROM `MARC Records by Number`");
  
  $n_array = array();
  while($row = $results-&gt;fetch_assoc()) {
      $n_array[] = $row["OCLC Number"];
  }
  
  d($n_array);
  foreach($n_array as $k =&gt; $val) {
      print $val . " ";
  }
  
  /* 8 digits */
  $counter = 10000000;
  $master_array = array();
  
  /* 10 digits */
  while ($counter &lt;= 9999999999 ) {
      $master_array[] = $counter;
      $counter++;
      d($master_array);
  }
  d($master_array);    
  
  $missing_numbers_ar = array_diff ($master_array, $n_array);
  d($missing_numbers_ar);
  </code></pre>
  
  <p>d() is a custom function akin to var_dump().</p>
  
  <p>However, I just realized it would take tons of time for this to be done. At the 15 minute mark, $master_array is being populated with only 4000 numbers.</p>
  
  <p>How can I do this in a quicker way? MySQL-only or MySQL-and-PHP solutions both welcome. If the optimal solution depends on how many numbers are missing, please let me know how so. Tq.</p>