title: Optimizing big string arrays for checking if a string exists queries
body: <p>I have a big array that contains string values as the data. I want to optimize this array, so I can perform queries that check if a certain string exists in the array as quickly as possible. So let's say I create the array with <code>$arr= [];</code> and then add values like this:</p>
  
  <pre><code>foreach($names as $name)
      $arr[]= $name;
  </code></pre>
  
  <p>And now I want to perform a lot of queries like <code>if(in_array($random_string, $arr))</code>, but it's pretty slow. I'd like to add some indexing for the array to optimize the performance. Should I simply use the <code>sort()</code> function for the array? </p>
  
  <p>How to optimize an array with string data for checking if a string exists queries?</p>
  
  <p><em>EDIT: No, obviously this is not a duplicate of "what is faster: in_array or isset? [closed]", and you can see that already by the answer by vivek_23.</em></p>