title: Efficient way to delete multiple elements from PHP array
body: <p>I have a dynamically generated array of filenames, let's say it looks something like this:</p>
  
  <pre><code>$files = array("a-file","b-file","meta-file-1", "meta-file-2", "z-file");
  </code></pre>
  
  <p>I have a couple of specific filenames that I want discarded from the array:</p>
  
  <pre><code>$exclude_file_1 = "meta-file-1";
  $exclude_file_2 = "meta-file-2";
  </code></pre>
  
  <p>So, I'll always know the values of the elements I want discarded, but not the keys.</p>
  
  <p>Currently I'm looking at a couple of ways to do this.
  One way, using array_filter and a custom function:</p>
  
  <pre><code>function excludefiles($v)
          {
          if ($v === $GLOBALS['exclude_file_1'] || $v === $GLOBALS['exclude_file_2'])
            {
            return false;
            }
          return true;
          }
  
  $files = array_values(array_filter($files,"excludefiles"));
  </code></pre>
  
  <p>Another way, <a href="https://stackoverflow.com/questions/7884991/php-better-way-to-unset-multiple-array-elements">using array_keys and unset</a>:</p>
  
  <pre><code>$exclude_files_keys = array(array_search($exclude_file_1,$files),array_search($exclude_file_2,$files));
  foreach ($exclude_files_keys as $exclude_files_key)
      {    
      unset($files[$exclude_files_key]);
      }
  $files = array_values($page_file_paths);
  </code></pre>
  
  <p>Both ways produce the desired result.</p>
  
  <p><strong>I'm just wondering which one would be more efficient (and why)?</strong></p>
  
  <p><strong>Or perhaps there is another, more efficient way to do this?</strong></p>
  
  <p>Like maybe there's a way to have multiple search values in the array_search function?</p>