Fast prefix match
<p>I need to match a certain number of prefixes for a list of strings, and gather only the strings that have one of those prefixes, like this:</p>

<pre><code>$prefixes = array('Dr.', 'Prof.', 'Atty.', 'Rev.');

$results = array();

foreach($names as $name){

  $this_prefix = false;

  foreach($prefixes as $prefix){
    if(strpos($name, $prefix) === 0){
      $this_prefix = $prefix;
    }
  }

  if($this_prefix !== false){
    $name = substr($name, strlen($prefix) + 1);
    $results[$this_prefix][] = $name;
  }

}
</code></pre>

<p>The code above does the job, but is there any faster solution?</p>
