title: PHP in_array() horrible performance. Fatest way to search array for value
body: <p>I have the following simple code to test against collision on a primary key I am creating:</p>
  
  <pre><code>$machine_ids = array();
  
  for($i = 0; $i &lt; 100000; $i++) {
      //Generate machine id returns a 15 character alphanumeric string
      $mid = Functions::generate_machine_id();
  
      if(in_array($mid, $machine_ids)) {
          die("Collision!");
      } else {
          $machine_ids[] = $mid;  
      }
  }
  
  die("Success!");
  </code></pre>
  
  <p>Any idea why this is taking many minutes to run? Anyway to speed it up?</p>