title: Remove elements from an array that do not match a regex
body: <p>In PHP, is there a function or anything else that will remove all elements in an array that do not match a regex.</p>
  
  <p>My regex is this: <code>preg_match('/^[a-z0-9\-]+$/i', $str)</code></p>
  
  <p>My array's come in like this, from a form (they're tags actually)</p>
  
  <p><strong>Original array from form. Note: evil tags</strong></p>
  
  <pre><code>$arr = array (
      "french-cuisine",
      "french-fries",
      "snack-food",
      "evil*tag!!",
      "fast-food",
      "more~evil*tags"
  );
  </code></pre>
  
  <p><strong>Cleaned array. Note, no evil tags</strong></p>
  
  <pre><code>Array (
      [0] =&gt; french-cuisine
      [1] =&gt; french-fries
      [2] =&gt; snack-food
      [3] =&gt; fast-food
  )
  </code></pre>
  
  <p>I currently do like this, but is there a better way? Without the loop maybe?</p>
  
  <pre><code>foreach($arr as $key =&gt; $value) {
      if(!preg_match('/^[a-z0-9\-]+$/i', $value)) {
          unset($arr[$key]);
      }
  }
  
  print_r($arr);
  </code></pre>