We can simplify this logic with the following code:
```php
foreach ($tplphpfiles as $filename) {
  if ($template_name = strstr($filename, '.tpl.php', TRUE)) {
    $template_as_key = str_replace('-', '_', $template_name);
    $template_array[$template_as_key] = array('template' => $template_name);
  }
}
```